下面这个类是我以前写的。
你只需稍做修改函数名就可以了,且功能大得多。
输出的话。
cout<<"after moving…" << p <
template
class point
{
public:
T x;
T y;
point() {};
point(T a,T b)
{
x = a;
y = b;
}
point(const point
{
x = a.x;
y = a.y;
}
point
{
x = p.x;
y = p.y;
}
friend point
{
point
return p;
}
void MoveTo(T a,T b)
{
x = a;
y = b;
}
void SetX(T a)
{
x = a;
}
void SetY(T a)
{
y = a;
}
T GetX()
{
return x;
}
T GetY()
{
return y;
}
friend T crossProduct(point
{
return p1.x * p2.y - p1.y * p2.x;
}
friend T direction(point
{
return crossProduct(p1 - pO, p2 - pO);
}
friend bool operator == (point
{
return (abs(p1.x - p2.x) < EP && abs(p1.y - p2.y) < EP);
}
friend T dist(point
{
return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
}
friend istream& operator >> (istream& input, point
{
input >> p.x;
input >> p.y;
return input;
}
friend ostream& operator << (ostream& output, point
{
output << p.x << ' ' << p.y;
return output;
}
};