我有这个代码:
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/