[英]Boost asio TCP IP asio class compile error with Visual Studio. Error: C2228: left of '.close' must have class/struct/union
I'm trying to follow the steps provided in this page我正在尝试按照此页面中提供的步骤进行操作
http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/tutorial/tutdaytime1.html http://www.boost.org/doc/libs/1_46_0/doc/html/boost_asio/tutorial/tutdaytime1.html
However, at some point the code does not compile, and gives me the specified error.但是,在某些时候代码无法编译,并给我指定的错误。 I can't understand what kind of conflict it is.
我无法理解这是一种什么样的冲突。 The object tcpsock doesn't seem to be correctly created.
对象 tcpsock 似乎未正确创建。 Please check my code:
请检查我的代码:
io_service io_tcp;
tcp::resolver resolverObject(io_tcp);
tcp::resolver::query queryObject(argv[1], "daytime");
tcp::resolver::iterator endpoint_iterator = resolverObject.resolve(queryObject);
tcp::resolver::iterator end; //default constructor is end iterator
tcp::socket tcpsock(io_service);
boost::system::error_code socketError = boost::asio::error::host_not_found;
while (socketError && endpoint_iterator != end)
{
//Apparently, the object isn't created correctly
tcpsock.close(); //error happenes here
tcpsock.connect(*endpoint_iterator++, socketError); //error happenes here too
}
if (socketError)
throw boost::system::system_error(socketError);
Thank you for any efforts.感谢您的任何努力。
要初始化tcpsock
与类型io_service
,而不是与变量io_tcp
。
I also found this compile error but from a different angle given the following:我也发现了这个编译错误,但从不同的角度给出了以下内容:
boost::asio::read(socket, replyBuf, boost::asio::transfer_all(), error);
Compared to the correct:与正确的相比:
boost::asio::read(*socket, replyBuf, boost::asio::transfer_all(), error);
Notice the need the de-reference the socket.请注意需要取消引用套接字。 It seems boost's use of common base types prevents the usual intellisense errors.
似乎 boost 使用常见的基本类型可以防止常见的智能感知错误。
In the future I recommend adding a null check before use for the args of a boost type at runtime.将来,我建议在运行时为 boost 类型的参数使用之前添加空检查。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.