http://en.wikipedia.org/wiki/Auto_ptr
auto_ptr은 smart pointer 기법가운데 하나이다. 인용하면
auto_ptr is a template class available in the C++ Standard Library(declared in
The auto_ptr template class describes an object that stores a pointer to an allocated object of type Type* that ensures that the object to which it points gets destroyed automatically when control leaves a scope.
ex)
int *i = new int;
auto_ptr
auto_ptr
y = x;
cout << x.get() << endl;
cout << y.get() << endl;
This code will print a NULL address for the first auto_ptr object and some non-NULL address for the second, showing that the source object lost the reference during the assignment (=). The raw pointer i in the example should not be deleted, as it will be deleted by the auto_ptr that owns the reference.
'Papers > programming' 카테고리의 다른 글
template inline (0) | 2008.05.27 |
---|---|
Template class (0) | 2008.05.27 |
new & delete overloading (0) | 2008.05.26 |
operator overloading (0) | 2008.05.26 |
class type down-casting (0) | 2008.04.29 |