C++实验(一)CMatrix类设计与实现


CMatrix类的实现

1、头文件声明:CMatrix.h

#ifndef CMATRIX_H
#define CMATRIX_H

#include <iostream>
using namespace std;

class CMatrix
{
   
public:
	//构造器
	CMatrix();
	CMatrix(int nRow, int nCOl, double* pData = NULL);
	CMatrix(const CMatrix& m);
	CMatrix(const char* strPath);
	//析构函数
	~CMatrix();
	//初始方法
	bool Create(int nRow, int nCol, double* pData = NULL);
	//释放内存方法
	void Release();
	//内联函数
	void Set(int nRow, int nCol, double dVale);
	//友元函数,允许一个函数或类访问类的私有属性
	//重载操作符
	friend istream& operator>>(istream& is, CMatrix& m);
	friend ostream& operator<<(ostream& os, const CMatrix& m);
	//重载运算符
	CMatrix& operator=(const CMatrix& m);
	CMatrix& operator+=(const CMatrix& m);
	CMatrix& operator-=(const CMatrix& m);
	bool operator == (const CMatrix& m);
	bool operator != (const CMatrix& m);

	double& operator[](int nIndex);
	double& operator()(int nRow, int nCol);
	//重载类型转换
	operator double();


private:
	int m_nRow;
	int m_nCol;
	double* m_pData = NULL;
};
//重载“+”运算符
CMatrix operator+(const CMatrix& m1, const CMatrix& m2);
//重载“-”运算符
CMatrix operator-(const CMatrix& m1, const CMatrix& m2);

//内联函数(修改矩阵某元素的值)
//在编译时,编译器会把内联函数的代码块放置在每个调用该函数的地方
inline void CMatrix::Set</
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值