库更新

This commit is contained in:
iridiumR 2022-03-15 17:09:38 +08:00
parent cacff0155b
commit 70e545a4ef

View file

@ -2,7 +2,7 @@
* @Author: iR * @Author: iR
* @Date: 2022-03-11 16:44:46 * @Date: 2022-03-11 16:44:46
* @LastEditors: iR * @LastEditors: iR
* @LastEditTime: 2022-03-12 17:25:28 * @LastEditTime: 2022-03-15 17:02:42
* @FilePath: \Code\inc\matrix.hpp * @FilePath: \Code\inc\matrix.hpp
* @Description: * @Description:
* *
@ -17,7 +17,15 @@
#include "../inc/vector.hpp" #include "../inc/vector.hpp"
template <class T> template <class T>
class Matrix class MatBase
{ // 定义基类,其中包含了矩阵元素读取的纯虚函数
public:
virtual T &at(int y, int x) = 0; // 定义纯虚函数
virtual const T &at(int y, int x) const = 0; // 定义纯虚函数
};
template <class T>
class Matrix : public MatBase<T>
{ {
private: private:
int _height; int _height;
@ -91,7 +99,7 @@ public:
/** /**
* @description: = * @description: =
*/ */
T operator=(const Matrix &b); void operator=(const Matrix &b);
/** /**
* @description: += * @description: +=
@ -100,6 +108,13 @@ public:
* @return None * @return None
*/ */
void operator+=(const Matrix &b); void operator+=(const Matrix &b);
void operator+=(T &a)
{
for (int i = 0; i < _width * _height;i++)
{
_mat[i] = a;
}
}
/** /**
* @description: += * @description: +=
@ -236,7 +251,7 @@ Matrix<T>::Matrix(const Matrix &another)
} }
template <class T> template <class T>
T Matrix<T>::operator=(const Matrix &another) void Matrix<T>::operator=(const Matrix &another)
{ {
try try
{ {
@ -245,6 +260,7 @@ T Matrix<T>::operator=(const Matrix &another)
_mat = new Vector<T>; _mat = new Vector<T>;
for (int i = 0; i < _width * _height; i++) for (int i = 0; i < _width * _height; i++)
_mat->put(i, another[i]); _mat->put(i, another[i]);
} }
catch (const char *msg) catch (const char *msg)
{ {
@ -278,12 +294,6 @@ void Matrix<T>::operator+=(const Matrix &b)
} }
} }
/**
* @description: +=
* @note: c = a + b*this即为ac
* @param {*}
* @return None
*/
template <class T> template <class T>
Matrix<T> Matrix<T>::operator+(const Matrix &b) const Matrix<T> Matrix<T>::operator+(const Matrix &b) const
{ {