求求c++高手帮忙看看这个运算符重载问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 02:46:18
这个矩阵类程序已经运行,而且其它都对,别的+,*,/运算符重载都成功了,只是“-”号,系统当做“负号”了,实际我做的是“减号”,我希望不用友元函数,那个我更弄不明白,希望哪个高人帮我在这个基础上改一改!!

只是部分程序:
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

const int MaxRow = 3;
const int MaxCol = 3;
class Matrix
{
public:
Matrix();
~Matrix(){}
int row() {return rowNum;}//得到某行数
int col() {return colNum;}//得到列行数
void setRow(int newRow) { rowNum=newRow;}//重置行数
void setCol(int newCol) { colNum=newCol;}//重置列数
void set(int newRow,int newCol); //重置某一元素
double & get(int r, int c);//得到某元素的值
void initialize(); //系统自动定义矩阵初始值
void display();//自定义矩阵初始值
Matrix & operator +(Matrix other);// 重载加法运算符+,将两个矩阵相加。
Matrix & operator -(Matrix other);//重载加法运算符-,将两个矩阵相减。
Matrix & operator *(Matrix other);//重载加法运算符*,将两个矩阵相乘。
Matrix & operator =(Matrix other);// 重载赋值运算符=,将一个矩阵赋给另外一个矩阵。
double

#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

const int MaxRow = 3;
const int MaxCol = 3;
class Matrix
{
public:
Matrix(){};
~Matrix(){};
int row()
{
return rowNum; //得到某行数
}
int col()
{
return colNum; //得到列行数
}
void setRow(int newRow)
{
rowNum=newRow; //重置行数
}
void setCol(int newCol)
{
colNum=newCol; //重置列数
}
void set(int newRow,int newCol); //重置某一元素
double & get(int r, int c);//得到某元素的值
void initialize(); //系统自动定义矩阵初始值
void display();//自定义矩阵初始值
Matrix operator +(Matrix other);// 重载加法运算符+,将两个矩阵相加。
Matrix operator -(Matrix other);//重载加法运算符-,将两个矩阵相减。
Matrix & operator *(Matrix other);//重载加法运算符*,将两个矩阵相乘。