65,186
社区成员




#include<iostream>
using namespace std;
class Vector
{
friend ostream& operator<<(ostream& out,const Vector &a);
friend istream& operator>>(istream& in,Vector &a);
public:
Vector(int x=0, int y=0, int z=0);
Vector operator+(const Vector& s)const;
int operator[](const Vector& s)const;
private:
int x, y, z;
};
Vector::Vector(int x, int y , int z)
{
this->x = x;
this->y = y;
this->z = z;
}
ostream& operator<<(ostream& out, const Vector &a)
{
if (a.x != 0)
out << a.x << "i+";
if (a.y != 0)
out << a.y << "j+";
if (a.z != 0)
out << a.z << "z";
if (a.x ==0&& a.y ==0&& a.z==0)
out << "0";
return out;
}
istream& operator>>(istream& in, Vector &a)
{
in >> a.x;
in >> a.y;
in >> a.z;
return in;
}
Vector Vector::operator+(const Vector& s)const
{
Vector t;
t.x = x + s.x;
t.y = y + s.y;
t.z = z + s.z;
return t;
}
int Vector::operator[](const Vector& s)const
{
return s.x + s.y + s.z; //模长表达式不对,,,只是测试一下
}
void main()
{
Vector b(1,1,1);
cout <<[b]; //报错
}
int Vector::normal();