auto_ptr的应用

原创 hamo  2006-09-13 14:33  阅读 1,013 views 次

template<class T>
class auto_ptr {
public:
typedef T element_type;
explicit auto_ptr(T *p = 0) throw();
auto_ptr(const auto_ptr<T>& rhs) throw();
auto_ptr<T>& operator=(auto_ptr<T>& rhs) throw();
~auto_ptr();
T& operator*() const throw();
T *operator->() const throw();
T *get() const throw();
T *release() const throw();
};
The class describes an object that stores a pointer to an allocated object
of type T. The stored pointer must either be null or designate an object
allocated by a new expression. The object also stores an ownership
indicator. An object constructed with a non-null pointer owns the pointer.
It transfers ownership if its stored value is assigned to another object.
The destructor for auto_ptr<T> deletes the allocated object if it owns it.
Hence, an object of class auto_ptr<T> ensures that an allocated object is
automatically deleted when control leaves a block, even via a thrown
exception.

-----
可以自动释放对象。

auto_ptr<C> p(new C());
p->DoSomething();

本文地址:https://www.satwe.com/archives/376.html
关注我们:请关注一下我们的微信公众号:扫描二维码哈默博客的公众号,公众号:aiboke112
版权声明:本文为原创文章,版权归 hamo 所有,欢迎分享本文,转载请保留出处!

发表评论


表情