#include<iostream
using namespace std
int i;
class Vector
{
public:
Vector()
friend istream &operator<<(istream&in,Vector Y);
friend ostream &operator<<(ostream&ou,Vector Y);
Vector operator + (Vector &Y);
Vector operator - (Vector &Y);
Vector operator == (Vector &Y);
//private:
double a[10];
};
Vector::Vector()
{
for(i=0;i<10;i++)
a[i]=0;
}
istream &operator>>(istream&in,Vector Y)
{
for(i=0;i<10;i++)
in >>Y.a[i];
return in;
}
ostream &operator<<(ostream&ou,Vector Y)
{
ou <<"(";
for(i=0;i<10;i++)
{
ou <<Y.a[i];
if(i==9)
ou <<")"<<endl;
else
ou <<",";
}
return ou;
}
Vector Vector::operator + (Vector &Y)
{
Vector sum;
for(i=0;i<10;i++)
sum.a[i]=a[i]+Y.a[i];
cout<<"两向量相加:"<<endl;
return sum;
}
Vector Vector::operator - (Vector &Y)
{
Vector sub;
for(i=0;i<10;i++)
sub.a[i]=a[i]-Y.a[i];
cout<<"两向量相减:"<<endl;
return sub;
}
main()
{
Vector X,Y,M,N
cin>>X>>Y;
M=X+Y
cout<<X<<endl<<Y<<endl<<M<<endl;
M=X-Y;
cout<<X<<endl<<Y<<endl<<M<<endl;
}
为什么我的输入没有给主函数的对象赋值????
using namespace std
int i;
class Vector
{
public:
Vector()
friend istream &operator<<(istream&in,Vector Y);
friend ostream &operator<<(ostream&ou,Vector Y);
Vector operator + (Vector &Y);
Vector operator - (Vector &Y);
Vector operator == (Vector &Y);
//private:
double a[10];
};
Vector::Vector()
{
for(i=0;i<10;i++)
a[i]=0;
}
istream &operator>>(istream&in,Vector Y)
{
for(i=0;i<10;i++)
in >>Y.a[i];
return in;
}
ostream &operator<<(ostream&ou,Vector Y)
{
ou <<"(";
for(i=0;i<10;i++)
{
ou <<Y.a[i];
if(i==9)
ou <<")"<<endl;
else
ou <<",";
}
return ou;
}
Vector Vector::operator + (Vector &Y)
{
Vector sum;
for(i=0;i<10;i++)
sum.a[i]=a[i]+Y.a[i];
cout<<"两向量相加:"<<endl;
return sum;
}
Vector Vector::operator - (Vector &Y)
{
Vector sub;
for(i=0;i<10;i++)
sub.a[i]=a[i]-Y.a[i];
cout<<"两向量相减:"<<endl;
return sub;
}
main()
{
Vector X,Y,M,N
cin>>X>>Y;
M=X+Y
cout<<X<<endl<<Y<<endl<<M<<endl;
M=X-Y;
cout<<X<<endl<<Y<<endl<<M<<endl;
}
为什么我的输入没有给主函数的对象赋值????