void f(boost::shared_ptr<int> ptr)
{
if (ptr) // should we check?
// do something
}
void f2(int *p)
{
if (p) // good practice to check before using it
// do something
}
问题:我们在使用前应验证shared_ptr
吗?在使用之前,我应该检查boost :: shared_ptr或std :: shared_ptr吗?
只需使用** use_count **函数检查引用的数量,并且没有要检查的内容。 – softghost 2012-03-15 21:05:41