class Vector;
class Matrix
{
public:
Matrix(int,int);
~Matrix(){delete []m;}
Matrix(Matrix &);
int &Elem(int,int);
friend Vector Multiply(Matrix &m,Vector &v);
protected:
int *m;
int szl;
int szr;
};
class Vector
{
public:
Vector(int);
~Vector(){delete []v;}
Vector(Vector &);
void Display();
int &Elem(int);
friend Vector Multiply(Matrix &m,Vector &v);
protected:
int*v;
int sz;
};
void Vector::Display()
{
for(int i=0;i<sz;i++)
cout<<v[i]<<" ";
cout<<endl;
}
void main()
{
Matrix ma(4,3);
ma.Elem(0,0)=1;
ma.Elem(0,1)=2;ma.Elem(0,2)=3;
ma.Elem(1,0)=0;ma.Elem(1,1)=1;ma.Elem(1,2)=2;
ma.Elem(2,0)=1;ma.Elem(2,1)=1;ma.Elem(2,2)=3;
ma.Elem(3,0)=1;ma.Elem(3,1)=2;ma.Elem(3,2)=1;
Vector ve(3);
ve.Elem(0)=2;ve.Elem(1)=1;ve.Elem(2)=0;
Vector va=Multiply(ma,ve); //调试到这里出错,错误信息就是:unhandled exception in *:0XC0000005 :Access violation
va.Display();
}