#ifndef _MATRIX_HPP_ #define _MATRIX_HPP_ #include "../inc/vector.hpp" template class Matrix { private: int _height; int _width; Vector *_mat; protected: public: // 确定矩阵元素大小,不初始化 Matrix(int w, int h); // 以相同值初始化矩阵元素 Matrix(int w, int h, T init_value); // 以顺序访问数组的值初始化矩阵元素 Matrix(int w, int h, const double *elements); // 以另一个矩阵初始化当前矩阵的元素,实际是元素拷贝 Matrix(const Matrix &another); //只读访问内容 const T get(int w, int h) const; //运算符重载 T &operator[](int i) { return _mat[i]; } }; template Matrix::Matrix(int w, int h) { _width = w; _height = h; _mat = new Vector(w * h); } template Matrix::Matrix(int w, int h, T init_value) { _width = w; _height = h; _mat = new Vector(w * h, init_value); } template const T Matrix::get(int w, int h) const { return _mat[w * _width + h]; } #endif