#include <iostream>

using namespace std;


class Point {

int x, y;


public:

Point(int _x = 0, int _y = 0) :x(_x), y(_y) {}

void Print() const {

cout << x << ", " << y << endl;

}

const Point operator+(const Point &arg) const

{

Point pt;

pt.x = this->x + arg.x;

pt.y = this->y + arg.y;


return pt;

}


const Point& operator++()

{

++x;

++y;


return *this;

}

const Point operator++(int)

{

Point pt(x, y);

++x;

++y;

return pt;

}

};


int main()

{

Point pt1(2, 3);

Point pt2(3, 5);

++pt2;

Point pt3;

pt3 = pt1 + pt2;


pt3.Print();

pt2.Print();

return 0;

}

'Programing > C++' 카테고리의 다른 글

형변환 연산자 오버로딩  (0) 2015.09.04
-> , * 연산자 오버로딩  (0) 2015.09.02
구조체로 구현한 Invader  (0) 2015.06.09
클래스 template  (0) 2015.04.27
함수 Template  (0) 2015.04.27
Posted by kimmayer

블로그 이미지
IT 기술들 정리, 독후감을 주로 남깁니다!
kimmayer

공지사항

Yesterday
Today
Total

달력

 « |  » 2024.4
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함