读书人

boost库的shared_ptr如何当类的成员变

发布时间: 2012-09-21 15:47:26 作者: rapoo

boost库的shared_ptr怎么当类的成员变量用
在一个类中,不用这个智能指针时,可以直接定义一个变量,比如int* m_pInt,然后在构造函数或初始化函数之类的地方写m_pInt = new int[111];
现在想要把m_pInt换shared_ptr<int> m_pInt的,要怎么做呢?

[解决办法]
shared_ptr<int> m_pInt2 = shared_ptr<int>(m_pInt);
[解决办法]
reset(new int(300));

ok?



探讨
引用:
shared_ptr<int> m_pInt2 = shared_ptr<int>(m_pInt);

...感觉有点脱裤子放屁啊

读书人网 >C++

热点推荐