
Smart Pointer
vv_VV_vv
这个作者很懒,什么都没留下…
展开
-
3.weak_ptr
weak_ptr循环引用:引用计数是一种便利的内存管理机制,但它有一个很大的缺点,那就是不能管理循环引用的对象。一个简单的例子如下:#include #include #include #include class parent;class children;typedef boost::shared_ptr parent_ptr;typed转载 2013-01-02 00:46:27 · 630 阅读 · 0 评论 -
4.shared_ptr
shared_ptr简介scoped_ptr虽然简单易用,但它不能共享所有权的特性却大大限制了其使用范围,而shared_ptr可以解决这一局限。顾名思义,shared_ptr是可以共享所有权的智能指针//Form vs2010 header #include //// include auto_ptr shared_ptr weak_ptr unique_ptr in v原创 2013-01-02 00:58:31 · 1139 阅读 · 0 评论 -
1.auto_ptr
auto_ptr简介auto_ptr一个对象只有一个拥有者(一个萝卜一个坑,两个auto_ptr不能同时拥有同一个对象)注:对于智能指针可以参看《Beyond the C++ Standard Library:An Introduction to Boost》、《boost_1_41_0_doc》地址:http://code.google.com/p/boost-doc原创 2013-01-01 23:49:33 · 830 阅读 · 0 评论 -
2.scoped_ptr
boost::scoped_ptr和std::auto_ptr非常类似,是一个简单的智能指针,它能够保证在离开作用域后对象被自动释放。下列代码演示了该指针的基本应用:#include #include #include class implementation{public: ~implementation() { std::c转载 2013-01-02 00:43:30 · 572 阅读 · 0 评论