Matrix.h
#ifndef __MATRIX_H__
#define __MATRIX_H__
class Matrix
{
public:
Matrix(int row, int col); //普通构造函数
Matrix(const Matrix& matrix); //拷贝构造函数
Matrix(); //构造空矩阵的构造函数
Matrix& operator = (const Matrix& matrix); //重载"="操作符
Matrix& operator += (const Matrix& matrix); //重载"+="操作符
int Row(void)const {
return m_nRow; } //返回矩阵的行数
int Col(void)const {
return m_nCol; } //返回矩阵的列数
~Matrix(); //析构函数
//重载"+"操作符
friend
Matrix operator + (const Matrix& x, const Matrix& y);
friend
Matrix operator + (const Matrix& matrix, double x);
friend
Matrix operator + (double x, const Matrix& matrix);
//重载"-"操作符
friend
Matrix operator - (const Matrix& x, const Matrix& y);
friend
Matrix operator - (const Matrix& matrix, double x);
friend
Matrix operator - (double x, const Matrix& matrix);
//重载"*"操作符
friend
Matrix operator * (const Matrix& x, const Matrix& y);
friend
Matrix operator * (const Matrix& matrix, double x);
friend
Matrix operator * (double x, const Matrix& matrix);
//输出矩阵的函数
friend
void OutPut(const Matrix& matrix);
//计算点乘的函数
friend
double __DOTMUL(const Matrix& x, const Matrix&y, int nR, int nC);
private:
int m_nRow; //矩阵的行数
int m_nCol; //矩阵的列数
double **m_pBuf; //存储矩阵的空间
};
#endif
Matrix.cpp
//*****头文件*****//
#include "Matrix.h"
#include <iostream>
//*****命名空间*****//
using namespace std;
//*****函数定义*****//
//普通构造函数
inline
Matrix::Matrix(int row, int col)
:m_nRow(row), m_nCol(col)
{
m_pBuf = new double*[m_nRow];
for (int i = 0; i < m_nRow; i++)
{
m_pBuf[i] = new double[m_nCol];
for (int j = 0; j < m_nCol; j&