boost库 智能指针

#include "boost/smart_ptr.hpp"

相当于同时 include 了各个智能指针(请查看smart_ptr.hpp源文件)

 

class User
{
    void print()
    {
        std::cout<<"test"<<std::endl;
    }
};

int main()
{
typedef boost::share_ptr<User> UserPtr;  
boost::shared_ptr<User>(new User) user_ptr1;
boost::shared_ptr<User>(new User) user_ptr2 = user_ptr1;  //shared_ptr 可以复制,貌似 scoped_ptr 不可以
user_ptr2->print()
boost::shared_ptr<User>(new User)->print();   //匿名
}

 

 

posted @ 2012-08-02 19:12  轻典  阅读(199)  评论(0编辑  收藏  举报