boost.asio test problem
I'm new on 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 privat开发者_运维百科e 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. As you can see, you must provide at least a reference to a boost::asio::io_service
object.
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.
You need to make a constructor that takes a io_service object and initialize your socket_ with the io_service.
Like so:
tcp_connection::tcp_connection(boost::asio::io_service& io_service) : socket_(io_service) {}
精彩评论