为什么 不能接受两个参数?~
#include "stdafx.h"using namespace std;
class vector
{int x,y;
public:
vector()
{x=y=0;}
vector(int X,int Y)
{x=X;
y=Y;
}
void display();
int getx();
int gety();
vector Add(const vector &ob2);
vector Sub(const vector &ob2 );
int Mult(const vector &ob2 );
};
void vector::display( )
{cout<<"x="<<x<<endl;
cout<<"y="<<y<<endl;
}
int vector::getx()
{return x;}
int vector::gety()
{return y;}
vector vector::Add(const vector &ob2 )
{int m,n;
cout<<"Enter Add x2"<<endl;
cin>>m;
cout<<"Enter Add y2"<<endl;
cin>>n;
vector ob3(m,n);
ob3.x=m+ob2.x;
ob3.y=n+ob2.y;
return ob3;
}
vector vector::Sub(const vector &ob2 )
{int m,n;
cout<<"Enter sub x2"<<endl;
cin>>m;
cout<<"Enter sub y2"<<endl;
cin>>n;
vector ob3(10,20);
ob3.y=ob2.y-n;
ob3.x=ob2.x-m;
return ob3;
}
int vector::Mult(const vector &ob2 )
{int q;
int m,n;
cout<<"Enter Mult x2"<<endl;
cin>>m;
cout<<"Enter Mult y2"<<endl;
cin>>n;
vector ob3(10,20);
q=m*ob2.x+n*ob2.y;
return q;
}
class Matrix
{vector lefttop(),righttop(),leftbottom(),rightbottom();
public:
Matrix()
{int m,n;
cout<<"Enter lefttop x:"<<endl;
cin>>m;
cout<<"Enter lefttop y:"<<endl;
cin>>n;
lefttop(m,n);
cout<<"Enter righttop x:"<<endl;
cin>>m;
cout<<"Enter righttop y:"<<endl;
cin>>n;
righttop(m,n);
cout<<"Enter leftbottom x:"<<endl;
cin>>m;
cout<<"Enter leftbottom y:"<<endl;
cin>>n;
leftbottom(m,n);
cout<<"Enter rightbottom x:"<<endl;
cin>>m;
cout<<"Enter rightbottom y:"<<endl;
cin>>n;
rightbottom(m,n);
}
void display( );
vector GetVector(int i, int j);
Matrix Add(const Matrix &ob2 );
Matrix Sub(const Matrix &ob2 );
int Mult(const Matrix &ob2 );
};
void Test1()
{int a,b,c,d,t;
cout<<"Enter x1"<<endl;
cin>>a;
cout<<"Enter y1"<<endl;
cin>>b;
vector A(a,b),M;
A.display();
c=A.getx();
d=A.getx();
cout<<"*************get*************"<<endl;
cout<<"x="<<c<<endl;
cout<<"y="<<d<<endl;
cout<<"******************************"<<endl;
M=A.Add(A);
cout<<"****After Add****************"<<endl;
M.display();
cout<<"******************************"<<endl;
M=A.Sub(A);
cout<<"****After sub****************"<<endl;
M.display();
cout<<"******************************"<<endl;
t=A.Mult(A);
cout<<"****After Mult****************"<<endl;
cout<<"the result:"<<t<<endl;
}
我编译出来,他说“Matrix::righttop”: 函数不接受 2 个参数。。。这是为什么