33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class CPoint {
private:
int x, y;
static int nCount;//用于保存点的个数
public:
CPoint() {}
int GetX() { return x; };
int GetY() { return y; }
void SetX(int nx) { x = nx; };
void SetY(int ny) { y = ny; };
friend istream& operator>>(istream& is, CPoint& p);
friend ostream& operator<<(ostream& is, CPoint& p);
};
istream& operator>>(istream& is, CPoint& p) { //成员函数重载》
int a, b;
is >> a >> b;
p.SetX(a);
p.SetY(b);
return is;
}
ostream& operator<<(ostream& os, CPoint& p) { //成员函数重载《
os << "<" << p.GetX() << "," << p.GetY() << ">";
return os;
}
int main() {
CPoint overloadCP;
cout << "Enter two numbers to make a point: " << endl;
cin >> overloadCP;
cout << overloadCP;
return 0;
}