#include<iostream>
using namespace std;
class point
{
public:
int x;
int y;
point(int x, int y) :x(x), y(y) {}
friend ostream& operator << (ostream &_cout, const point& p);
};
ostream& operator<< (ostream &_cout, const point& p)
{
_cout << "p.x=" << p.x << ",p.y=" << p.y << endl;
return _cout;
}
int main()
{
point p1(1, 2);
cout << p1;
return 0;
}
结果如下:
注意声明的具体格式: friend ostream& operator << (ostream &_cout, const point& p);