各位好,麻烦帮忙调试一下下面的程序啦!!谢谢!!
各位好,为什么我在运行下面的程序时,总是会出现内存问题的,各位帮忙看下啦!!!在此谢过啦!#include<iostream.h>
class Matrix{
public:
Matrix(int Row,int Column);//构造函数,形参为矩阵的行和列
Matrix(){}
~Matrix();//析构函数
Matrix operator+(const Matrix &m);//重载+运算符
Matrix operator-(const Matrix &m);//重载-运算符
//Matrix operator*(const Matrix &m);//重载*运算符
friend ostream &operator<<(ostream &output,const Matrix &m);//重载<<运算符
friend istream &operator>>(istream &input,const Matrix &m);//重载>>运算符
private:
int row;//矩阵的行数
int column;//矩阵的列数
int **ptr;//指向二维数组的指针
};
Matrix::Matrix(int Row,int Column)
{
row=Row;
column=Column;
ptr=new int*[row];
if(ptr!=NULL)
{
for(int i=0;i<row;i++)
{
ptr[i]=new int[column];
if(ptr[i]!=NULL)
cout<<**ptr;
}
}
}
Matrix::~Matrix ()
{
delete[]ptr;
}
Matrix Matrix::operator+(const Matrix &m)
{
Matrix temp;
ptr=new int*[row];
for(int k=0;k<row;k++)
ptr[k]=new int[column];
for(int i=0;i<m.row;i++)
{
for(int j=0;j<m.column;j++)
temp.ptr[i][j]=this->ptr [i][j]+m.ptr [i][j];
}
return temp;
}
Matrix Matrix::operator -(const Matrix &m)
{
Matrix temp;
ptr=new int*[row];
for(int k=0;k<row;k++)
ptr[k]=new int[column];
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
temp.ptr [i][j]=this->ptr[i][j]+m.ptr[i][j];
}
return temp;
}
istream &operator>>(istream &input,const Matrix &m)
{
for(int i=0;i<m.row;i++)
{
for(int j=0;j<m.column;j++)
input>>m.ptr [i][j];
}
return input;
}
ostream &operator<<(ostream &output,const Matrix &m)
{
for(int i=0;i<m.row;i++)
{
for(int j=0;j<m.column;j++)
output<<m.ptr [i][j];
}
return output;
}
int main()
{
int r,c;
cout<<"输入矩阵的行数r和列数c:"<<endl;
cin>>r>>c;
Matrix M1(r,c);
Matrix M2(r,c);
cout<<"输入c*r个元素:"<<endl;
cin>>M1;
cout<<"输入c*r个元素:"<<endl;
cin>>M2;
Matrix M3;
M3=M1+M2;
cout<<M3;
return 0;
}
--------------------编程问答-------------------- 出现什么问题? --------------------编程问答-------------------- 提示啥了呢 --------------------编程问答-------------------- C++... --------------------编程问答-------------------- 把错误信息贴出来看看 --------------------编程问答-------------------- 就是执行到这一步时就执行不了
temp.ptr [i][j]=this->ptr[i][j]+m.ptr[i][j];
说是:
"OxOO41337a"指令引用的"Oxcccccccc"内存。给内存不能为"read".
补充:.NET技术 , ASP.NET