c++ - boost::scoped_ptr 的 NULL 检查

标签 c++ boost

我是 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/

相关文章:

java - 如何用C、C++、Java等语言动态生成HTML?

c++ - 资源图像不工作 C++

c++ - 为什么我不能将 1 个元素分配给 2> 大小的动态选项卡?

c++ - 在没有小于谓词的情况下保持排序序列

visual-studio-2010 - 使用boost库的dll版本

c++ - Windows 上的 libboost_system

boost - 在测试可执行文件中使用特定类但在生产可执行文件中不使用 Boost 序列化的链接器错误

c++ - 是否可以在 C++ 中的表达式中定义变量?

c# - 无法在 C++ CLI 中维护指针集合

c++ - Boost 在序列化过程中丢失了一些数据