64,646
社区成员
发帖
与我相关
我的任务
分享
class X
{
public:
~X() { delete p; }
void fn(boost::shared_ptr<int> i)
{
p = i.get(); // 这儿应该增加i的引用计数
// 因为i中的指针我是放在析构函数中删除的.
// 该怎么增加i的引用计数?
}
private:
int* p;
};
void method()
{
boost::shared_ptr<int> i(new int(10));
X x;
x.fn(i);
}
class X
{
public:
~X() { delete p; }
void fn(boost::shared_ptr<int> i)
{
cout << i.use_count() << endl;
p = i.get(); // 该怎么增加i的引用计数? //引用计数不是自动增加的么?
cout << i.use_count() << endl;
}
private:
int* p;
};
void method()
{
boost::shared_ptr<int> i(new int(10));
X x;
x.fn(i);
}