#include<iostream>
#include<array>
template<typename T,size_t S>
class Array {
private:
T m_data[S];
public:
constexpr int Size()const {
return S;
}
T& operator[](int index) { return m_data[index]; }
const T& operator[](int index) const { return m_data[index]; }
T* Data() { return m_data; }
const T* Data()const { return m_data; }
};
int main() {
int size = 10;
Array<int, 10>data;
//static_assert(data.Size() < 8, "Size is too large!");
const auto& newdata = data;
memset(data.Data(), 0, data.Size() * sizeof(int));
for (int i = 0; i < data.Size(); i++) {
data[i] = 2;//data[i]是左值
std::cout << newdata[i] << std::endl;
}
}
标签:index,const,int,自己,return,数据结构,data,Size From: https://www.cnblogs.com/wangkaixin-yy/p/17822704.html