<<運算子重載:
#include <iostream>
using namespace std;
class Point{
privated:
int x, y;
public:
Point() {x = y = 0;}
Point(int x, int y){
this->x = x;
this->y = y;
}
friend ostream &operator<<(ostream &s, Point p);
};
ostream &operator<<(ostream &s, Point p) {
s << "("<< p.x << ", " << p.y << ")";
return s;
}
>>運算子重載:
#include <iostream>
using namespace std;
class Point {
privated:
int x, y;
public:
Point() { x = y = 0;}
Point(int x, int y) {
this->x = x;
this->y = y;
}
friend istream &operator>>(istream &s, Point &p);
};
istream &operator>>(istream &s, Point &p) {
cout << "輸入點座標: ";
s >> p.x >> p.y;
return s;
}
文章標籤
全站熱搜
