派生修改
This commit is contained in:
parent
35a9587d3d
commit
d63b1a8209
1 changed files with 321 additions and 311 deletions
30
SoftwareDesign/Code/inc/matrix.hpp
Normal file → Executable file
30
SoftwareDesign/Code/inc/matrix.hpp
Normal file → Executable 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即为a,返回值即为c
|
||||
* @param {*}
|
||||
* @return None
|
||||
*/
|
||||
template <class T>
|
||||
Matrix<T> Matrix<T>::operator+(const Matrix &b) const
|
||||
{
|
||||
|
|
Reference in a new issue