帮帮忙,重载运算符相关的
#include<iostream>using namespace std;
class Point
{
public:
Point() : x(0), y(0)
{
cout << "Initialize!" << endl;
}
Point(int a, int b) : x(a), y(b)
{
cout << "Initialize!" << endl;
}
friend ostream &operator << (ostream& output, Point& point);
friend istream &operator > (istream& input, Point &point);
~Point()
{
cout << "Set free!" << endl;
}
private:
int x, y;
};
ostream &operator << (ostream& output, Point& point)
{
output << "(" << point.x << "," << point.y << ")" << endl;
return output;
}
istream &operator>> (istream& input, Point &point)
{
input >> point.x;
input >> point.y;
return input;
}
int main()
{
Point A(3, 5), B;
cin >> B;
cout << A << endl << B << endl;
return 0;
}