库更新

This commit is contained in:
iridiumR 2022-03-15 17:09:38 +08:00
parent cacff0155b
commit 70e545a4ef
1 changed files with 20 additions and 10 deletions

View File

@ -2,7 +2,7 @@
* @Author: iR
* @Date: 2022-03-11 16:44:46
* @LastEditors: iR
* @LastEditTime: 2022-03-12 17:25:28
* @LastEditTime: 2022-03-15 17:02:42
* @FilePath: \Code\inc\matrix.hpp
* @Description:
*
@ -17,7 +17,15 @@
#include "../inc/vector.hpp"
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:
int _height;
@ -91,7 +99,7 @@ public:
/**
* @description: =
*/
T operator=(const Matrix &b);
void operator=(const Matrix &b);
/**
* @description: +=
@ -100,6 +108,13 @@ public:
* @return None
*/
void operator+=(const Matrix &b);
void operator+=(T &a)
{
for (int i = 0; i < _width * _height;i++)
{
_mat[i] = a;
}
}
/**
* @description: +=
@ -236,7 +251,7 @@ Matrix<T>::Matrix(const Matrix &another)
}
template <class T>
T Matrix<T>::operator=(const Matrix &another)
void Matrix<T>::operator=(const Matrix &another)
{
try
{
@ -245,6 +260,7 @@ T Matrix<T>::operator=(const Matrix &another)
_mat = new Vector<T>;
for (int i = 0; i < _width * _height; i++)
_mat->put(i, another[i]);
}
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>
Matrix<T> Matrix<T>::operator+(const Matrix &b) const
{