C++operator overloading座標運算

請問一下個為大大 我算出來的a有錯 可否請問是哪邊?? 要怎麼改?? #include <iostream> #include <cstdio> #include <cstdlib> using namespace std; class position { private: float x,y; public: position(float a,float b) { x=a;y=b; } position operator = (position rhs) { x=rhs.x; y=rhs.y; return... show more 請問一下個為大大
我算出來的a有錯 可否請問是哪邊??
要怎麼改??





#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
class position
{
private:
float x,y;
public:
position(float a,float b)
{
x=a;y=b;
}
position operator = (position rhs)
{
x=rhs.x; y=rhs.y;
return *this;
}
position operator - (position rhs)
{
position pass(0,0);
x=rhs.x-x; y=rhs.y-y;
return pass;
}
position operator / (position rhs)
{
position cool(0,0);
x=rhs.x/x; y=rhs.y/y;
return cool;
}
position operator * (position rhs)
{
position ans(0,0);
ans.x=rhs.x*x;ans.y=rhs.y*y;
return ans;
}
position operator + (position rights)
{
position answer(0,0);
answer.x=rights.x+x;answer.y=rights.y+...
return answer;
}
void print()
{
cout<<"("<<x<<","<<y<<")"<<endl;

}
};
int main()
{
position a(1,1),b(2,0),c(2,1);
a=((b*c)-a+c)/b;
cout<<"a的座標為"<<endl;
a.print();
cout<<"b的座標為"<<endl;
b.print();
cout<<"c的座標為"<<endl;
c.print();


system("pause");
return 0;
}
10 answers 10