c++ - 检查子成员是否为NULL

标签 c++ null visual-c++-2010

我有这个代码:

class Connection
{
public:
    boost::asio::ip::tcp::socket socket_;
}

void main()
{
   Connection* session = new Connection();
   //for example
   session->socket_.close() // FATAL ERROR PAGE FAULT
   // How to check whether child member socket_ is null? if(session->socket_ != NULL) - error : no operator != mathes these operands
}

当我尝试 if(session->socket_ != NULL) - 错误:没有运算符 != 数学这些操作数

我用的是VS2010

谢谢!

最佳答案

socket_ 不是指针,因此没有定义运算符来将它与 NULL 进行比较。也许你需要使用 is_open .

关于c++ - 检查子成员是否为NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19095329/

相关文章:

c++ - 具有unique_ptr成员的对象的错误C2280 vector

c++ - 在 C++11 中使用 max<int> 作为谓词中断

visual-studio-2010 - 我应该包含哪个头文件来使用 _swprintf_s()?

c++ - C++ 中的性能比较(普通函数调用与 for_each+mem_fun 与 lambda 表达式)

c++ - 这是一个 VC++2010 编译器错误吗?

c++ - 是否有对数时间插入、删除和查找(带距离)的排序数据结构?

c++ - Qt:将对象传递到每个窗口

sql - 如何知道a列是否包含所有NULL

c++ - HBITMAP hbm = LoadImage函数返回NULL

sql - 如果有值则返回该值。如果记录不存在或列为空,则在 Sql Server 中返回 0 - 不同的方式