#include
#include
class three_d
{
int x,y,z;
public:
friend three_d& operator+(three_d& a,int b);
friend three_d& operator+(int b,three_d& a);
three_d(int i,int j,int k)
{
x=i;
y=j;
z=k;
}
three_d()
{
x=0;
y=0;
z=0;
}
void get(int &i,int &j,int &k)
{
i=x;
j=y;
k=z;
}
void show()
{
cout<
};
three_d& operator+(three_d& a,int b)
{
a.x+=b;
a.y+=b;
a.z+=b;
return a;
}
three_d& operator+(int b,three_d& a)
{
a.x+=b;
a.y+=b;
a.z+=b;
return a;
}
void main()
{
three_d temp; //测试下,没问题
temp.show();
temp=temp+1;
temp.show();
}
希望能帮到你
class three_d;
three_d operator+(int,three_d); //这个函数是全局函数
three_d operator+(three_d,int);
class three_d
{
public:
friend three_d operator+(int,three_d);
friend three_d operator+(three_d,int);
protected:
private:
};
three_d operator+(int,three_d)
{
return three_d();
}
friend three_d *operator(int i)
{
this->x+=i;
this->y+=i;
this->z+=i;
return this;
}