急求用c++如何实现矩阵的定义和单位矩阵的定义

来源:百度知道 编辑:UC知道 时间:2024/06/05 02:30:08

#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

template < class T >
class CMatrix
{
public: //------------------ 构造部 -------------------------
CMatrix( void );
CMatrix( unsigned h, unsigned w );
CMatrix( const CMatrix& m );
CMatrix( const vector<T>& vec );
CMatrix( const vector<T>& vec,unsigned h,unsigned w );
~CMatrix(void);
private: //------------------- 数据部 ---------------------------
vector<T> m_vec_data;
unsigned m_u_width;
unsigned m_u_height;

public: // ------------------- 重载运算符 -------------------------

/// --- 以下均要求T具有如下运算能力:+ - += 等用到的。。。。

//取值运算
T& operator() ( unsigned row, unsigned col );
T operator() ( unsigned row, unsigned col ) const;

//赋值运算
CMatrix& operator = ( const CMatrix& );
CMatrix& operator +