【发布时间】:2018-08-14 16:23:05
【问题描述】:
我在阅读 The c++ Programming Language 4th edition 时遇到了这段代码
template<class T>
class Matrix {
array<int,2> dim; // two dimensions
T∗ elem; // pointer to dim[0]*dim[1] elements of type T
public:
Matrix(int d1, int d2) :dim{d1,d2}, elem{new T[d1∗d2]} {} // error handling omitted
int size() const { return dim[0]∗dim[1]; }
Matrix(const Matrix&); // copy constructor
Matrix& operator=(const Matrix&); // copy assignment
Matrix(Matrix&&); // move constructor
Matrix& operator=(Matrix&&); // move assignment
˜Matrix() { delete[] elem; }
// ...
};
类中有两个数据成员,其中一个是T 类型的指针。我不明白array< int, 2 > dim 是什么意思。
【问题讨论】:
标签: c++ arrays c++11 templates copy-constructor