#ifndef MATRIX_H
#define MATRIX_H
/************************************************************************/
/* 以下是C++实现 矩阵 类,Matrix 二元矩阵,数组存储;
/************************************************************************/
//matrix定义;
template <class Elemplent>
class CMatrix
{
private:
Elemplent *elemplentptr;
int rows,cols;
public:
CMatrix(int r = 0,int c= 0);
~CMatrix();
int Getrow()const;
int Getcol()const;
Elemplent & operator() (int r,int c);
CMatrix(const CMatrix<Elemplent> & tempmatrix);
CMatrix<Elemplent> & operator = (const CMatrix<Elemplent> & tempmatrix);
};
//构造函数
template<class Elemplent>
CMatrix<Elemplent>::CMatrix(int r /* = 0 */,int c/* = 0 */)
{
if (r <1 || c<1)
{
throw ERROR("row or col is error");
}
rows = r;
cols = c;
elemplentptr = new Elemplent [rows * cols];
}
//析构函数
template <class Elemplent>
CMatrix<Elemplent>::~CMatrix()
{
delete []elemplentp
数据结构——二维矩阵——数组实现(C++)
最新推荐文章于 2025-04-03 00:29:38 发布
本文介绍了使用C++模板类实现二维矩阵的数据结构,包括构造函数、析构函数、获取行列数、重载[]操作符以及赋值操作符等功能。

&spm=1001.2101.3001.5002&articleId=8950325&d=1&t=3&u=1af03f45a3be4609bd00cb17040937f0)
2597

被折叠的 条评论
为什么被折叠?



