http://blog.naver.com/yaiin0911?Redirect=Log&logNo=120022027021
#include <string>
#include <iostream>
#include <memory>
using namespace std;
void main()
{
auto_ptr<string> pStr(new string("AutoPtr Test"));
cout << *pStr << endl;
}
위의 코드에서 pStr은 string class를 직접 가리키지 않는다. 사실상 auto_ptr이라는 매개 class를 사용하게 된다. 그리고 main procedure에서 나갈 때(go out) auto_ptr이 destructor가 호출되고 그 안에서 string의 delete함수가 호출되게 된다.
'Papers > programming' 카테고리의 다른 글
#include "main.c" (0) | 2009.04.10 |
---|---|
Stack vs Heap Allocation (0) | 2008.10.08 |
try, catch and throw statements (0) | 2008.05.28 |
malloc vs. new (0) | 2008.05.28 |
template inline (0) | 2008.05.27 |