运算符+重载的问题
我学过c#的运算符重载,现在回过头学c++,发现c#的方法好像不能用 大家看一下我的代码哪里有问题,我是为了实现两个类之间能进行加法:
#include <iostream>
using namespace std;
class Three3d
{
public:
float x;
float y;
float z;
Three3d(float a,float b,float c);
Three3d operator+(Three3d left, Three3d right)
{
return Three3d(left.x+right.x,left.y+right.y,left.z+right.z);
}
void show();
};
inline Three3d::Three3d(float a,float b,float c)
{
x=a;
y=b;
z=c;
}
void Three3d::show()
{
cout<<x;
cout<<y;
cout<<z;
}
int main()
{
Three3d t1(50,20,10);
Three3d t2(10,10,5);
Three3d t3=t1+t2;
t3.show();
}