【发布时间】:2013-12-23 06:49:37
【问题描述】:
我有一个像 thsi 这样的课程:
class NotificationManager
{
public:
static NotificationManager* Instance()
{
try
{
static std::shared_ptr<NotificationManager> instance( new NotificationManager );
return instance.get();
}
catch( std::bad_alloc& )
{
return NULL;
}
}
void foo()
{
//do sth
}
}
如果我使用这个 foo 函数:
NotificationManager::Instance()->foo();
use_count 的值是多少?
这是一个好方法吗?如果不是有什么问题?
【问题讨论】:
标签: c++ memory-leaks shared-ptr smart-pointers