2015. 9. 2. 12:35 Programing/C++
-> , * 연산자 오버로딩
#include <iostream>
using namespace std;
class Point {
int x;
int y;
public:
Point(int _x = 0, int _y = 0) :x(_x), y(_y) {}
void Print() const { cout << x << ", " << endl; }
};
class PointPtr
{
Point *ptr;
public:
PointPtr(Point *p) :ptr(p) {}
~PointPtr() { delete ptr; }
Point* operator->() const
{
return ptr;
}
Point& operator*() const
{
return *ptr;
}
};
int main()
{
Point* p1 = new Point(2, 3);
PointPtr p2 = new Point(5, 5);
p1->Print();
p2->Print();
return 0;
}
p1은 일반 포인터, p2가 스마트 포인터
'Programing > C++' 카테고리의 다른 글
멤버 함수 포인터 선언 (0) | 2015.09.04 |
---|---|
형변환 연산자 오버로딩 (0) | 2015.09.04 |
간단한 오버라이딩 (0) | 2015.09.02 |
구조체로 구현한 Invader (0) | 2015.06.09 |
클래스 template (0) | 2015.04.27 |