我在阅读《C++程序设计语言第四版》时遇到了这段代码。
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
的意思。