diff --git a/SoftwareDesign/Code/inc/matrix.hpp b/SoftwareDesign/Code/inc/matrix.hpp index 968f51f..603469a 100644 --- a/SoftwareDesign/Code/inc/matrix.hpp +++ b/SoftwareDesign/Code/inc/matrix.hpp @@ -2,7 +2,7 @@ * @Author: iR * @Date: 2022-03-11 16:44:46 * @LastEditors: iR - * @LastEditTime: 2022-03-12 14:45:22 + * @LastEditTime: 2022-03-12 17:25:28 * @FilePath: \Code\inc\matrix.hpp * @Description: * @@ -28,7 +28,7 @@ protected: public: ~Matrix() { - delete[] _mat; + delete _mat; } /** * @description: 极度缺省初始化, 大小为2*2, 初值为0 @@ -60,14 +60,14 @@ public: */ Matrix(int w, int h, const T elements[]); - /** - * @description: 以顺序访问指针的值初始化矩阵元素 - * @note: 必须给出正确的数组,因为在函数内无法判定数组是否正确 - * @param {int} w - * @param {int} h - * @param {T*} data - */ - Matrix(int w, int h, T *data); + // /** + // * @description: 以顺序访问指针的值初始化矩阵元素 + // * @note: 必须给出正确的数组,因为在函数内无法判定数组是否正确 + // * @param {int} w + // * @param {int} h + // * @param {T*} data + // */ + // Matrix(int w, int h, T *data); /** * @description: 以另一个矩阵初始化当前矩阵的元素,实际是元素拷贝 @@ -117,7 +117,7 @@ public: */ T &at(int w, int h) { - double &ref = _mat->get(h * _width + w); + T &ref = _mat->get(h * _width + w); return ref; } @@ -129,7 +129,7 @@ public: */ const T &at(int w, int h) const { - double &ref = _mat->get(h * _width + w); + T &ref = _mat->get(h * _width + w); return ref; } @@ -186,36 +186,37 @@ Matrix::Matrix(int w, int h, const T elements[]) } } -template -Matrix::Matrix(int w, int h, T *data) -{ - int size = w * h; - try - { - //实际上似乎并不能在这里判断数组是否合法 - // if (w * h > size) - // throw "Error: The number of array elements is less than the matrix elements.\n"; - // if (w * h < size) - // throw "Error: The number of array elements is greater than the matrix elements.\n"; - if (data == NULL) - throw 1; - _width = w; - _height = h; - T temp; - _mat = new Vector; - for (int i = 0; i < size; i++) - _mat->put(i, *(data+sizeof(temp)*i)); - } - catch (const int a) - { - if (a == 1) - { - std::cout << "Error: Empty array. Set elements to 0." << std::endl; - for (int i = 0; i < size; i++) - _mat->put(i, 0); - } - } -} +//这个方法似乎有问题 +// template +// Matrix::Matrix(int w, int h, T *data) +// { +// int size = w * h; +// try +// { +// //实际上似乎并不能在这里判断数组是否合法 +// // if (w * h > size) +// // throw "Error: The number of array elements is less than the matrix elements.\n"; +// // if (w * h < size) +// // throw "Error: The number of array elements is greater than the matrix elements.\n"; +// if (data == NULL) +// throw 1; +// _width = w; +// _height = h; +// _mat = new Vector; +// for (int i = 0; i < size; i++) +// _mat->put(i, *(data+i)); +// } + +// catch (const int a) +// { +// if (a == 1) +// { +// std::cout << "Error: Empty array. Set elements to 0." << std::endl; +// for (int i = 0; i < size; i++) +// _mat->put(i, 0); +// } +// } +// } template Matrix::Matrix(const Matrix &another) diff --git a/SoftwareDesign/Code/inc/vector.hpp b/SoftwareDesign/Code/inc/vector.hpp index 8056b2c..ff61760 100644 --- a/SoftwareDesign/Code/inc/vector.hpp +++ b/SoftwareDesign/Code/inc/vector.hpp @@ -2,7 +2,7 @@ * @Author: iR * @Date: 2022-03-11 16:47:31 * @LastEditors: iR - * @LastEditTime: 2022-03-12 17:12:04 + * @LastEditTime: 2022-03-12 17:25:39 * @FilePath: \Code\inc\vector.hpp * @Description: * @@ -40,7 +40,7 @@ public: Vector(int len, T value); //析构函数 - // ~Vector() { delete[] _v; } + ~Vector() { delete[] _v; } //获取值 T &get(int a);