nakka soft world !
소멸자 본문
728x90
소멸자는 여러개 만들 수 없고, 1개만 만들 수 있음. 파라메터 없음.
소멸자를 만들지 않으면 컴파일러가 만듦.
class Point
{
private:
int x;
int y;
public:
Point() { cout << "Point()" << endl; }
void Destroy(Point* p) { delete p; }
private
~Point() { cout << "~Point()" << endl; }
};
int main()
{
//Point p1; // stack에 잡힘
Point* p1 = new Point; // heap에 잡힘
delete p1; // 접근 불가. Error
p1->Destroy(p1); // OK
}
728x90
'프로그래밍언어 > C++' 카테고리의 다른 글
복사 생성자 (Copy Constructor) (0) | 2017.03.17 |
---|---|
initialize list, 초기화 리스트 (0) | 2017.03.17 |
default function, delete function (0) | 2017.03.16 |
생성자 (construct) (0) | 2017.03.16 |
접근 지정자 (0) | 2017.03.16 |
Comments