更新引用库

This commit is contained in:
iridiumR 2022-03-12 14:49:02 +08:00
parent aae4fe2f26
commit 342c437437

View file

@ -2,7 +2,7 @@
* @Author: iR
* @Date: 2022-03-11 16:44:46
* @LastEditors: iR
* @LastEditTime: 2022-03-12 14:11:55
* @LastEditTime: 2022-03-12 14:45:22
* @FilePath: \Code\inc\matrix.hpp
* @Description:
*
@ -26,6 +26,10 @@ private:
protected:
public:
~Matrix()
{
delete[] _mat;
}
/**
* @description: , 2*2, 0
* @param {int} w
@ -49,13 +53,22 @@ public:
/**
* @description: 访
* @note: ,
* ,
* @param {int} w
* @param {int} h
* @param {const T} elements[]
*/
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:
* @param {Matrix} &another
@ -172,6 +185,38 @@ 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(const Matrix &another)
{