我是傻逼,我知道为啥了

This commit is contained in:
iridiumR 2022-03-12 17:26:10 +08:00
parent af7d67b808
commit 88f7d7107f
2 changed files with 45 additions and 44 deletions

View File

@ -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<T>::Matrix(int w, int h, const T elements[])
}
}
template <class T>
Matrix<T>::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<T>;
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 <class T>
// Matrix<T>::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<T>;
// 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 <class T>
Matrix<T>::Matrix(const Matrix &another)

View File

@ -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);