[英]boost.asio test problem
I'm new on boost.asio. 我是boost.asio的新手。 I have a problem when I try a simple example.
我尝试一个简单的示例时遇到问题。
in my header file I have: 在我的头文件中,我有:
#include <boost/asio.hpp>
#include "boost/bind.hpp"
#include "boost/date_time/posix_time/posix_time_types.hpp"
and I need this private variable: 我需要这个私有变量:
boost::asio::ip::udp::socket socket_;
I have this error at compile time: 我在编译时遇到此错误:
error C2512: 'boost::asio::basic_datagram_socket<Protocol>' : no appropriate default constructor available
with
[
Protocol=boost::asio::ip::udp
The list of all UDP socket constructors if found here . 如果可以在此处找到所有UDP套接字构造函数的列表。 As you can see, you must provide at least a reference to a
boost::asio::io_service
object. 如您所见,您必须至少提供对
boost::asio::io_service
对象的引用。
If this is a private variable, provide this reference in the class constructor's initializer list. 如果这是一个私有变量,请在类构造函数的初始化程序列表中提供此引用。 The following will compile:
将编译以下内容:
#include <boost/asio.hpp>
class Socket
{
boost::asio::ip::udp::socket socket_;
public:
Socket( boost::asio::io_service& ioserv) : socket_(ioserv) {}
};
int main()
{
boost::asio::io_service io;
Socket s(io);
}
I have used boost::asio and I had a similar issue. 我使用了boost :: asio,并且遇到了类似的问题。
You need to make a constructor that takes a io_service object and initialize your socket_ with the io_service. 您需要创建一个接受io_service对象的构造函数,并使用io_service初始化socket_。
Like so: 像这样:
tcp_connection::tcp_connection(boost::asio::io_service& io_service) : socket_(io_service) {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.