我是 boost 框架的新手,我不确定如何检查 scoped_ptr 中的对象是否为 null。
boost::scoped_ptr<CFoo> cFoo(new CFoo);
if(NULL != cFoo)
{
//todo
}
最佳答案
你可以做到
if(cFoo.get() != 0 ) //what you are trying to do
或者只是
if(cFoo) // as K-Ballo explains.
如 boost::scoped_ptr
所述
conversions
operator unspecified-bool-type () const; // never throws
Returns an unspecified value that, when used in boolean contexts, is equivalent to get() != 0.
关于c++ - boost::scoped_ptr 的 NULL 检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14372351/