Can't use boost.asio resolver in constructor

Hello,

I have a class, with attributs that i define line this :
1
2
3
4
5
6
7
8
private:
    const std::string m_ip;
    bool is_connected;
    boost::asio::io_service m_io_service;
    tcp::resolver m_resolver;
    tcp::resolver::query m_query;
    tcp::resolver::iterator m_endpoint_iterator;
    tcp::socket m_socket;

And the constructor implementations, that i define like this :
1
2
3
Connection::Connection(const std::string ip) : m_ip(ip), is_connected(false), m_resolver(tcp::resolver(&m_io_service)), m_query(tcp::resolver::query(m_ip, "connect_back")), m_endpoint_iterator(m_resolver.resolve(m_query)), m_socket(tcp::socket(m_io_service)){

}


Here, in this constructor, i define almost all the attributs like they need to be defined.
But, i have a problem that i never had in a full .cpp file : When i define the resolver in the constructor, the compiler say me that i've got an error :

1
2
3
4
/home/User/C++ Projects/Client/Network.cpp:9: error: no matching function for call to ‘boost::asio::ip::basic_resolver<boost::asio::ip::tcp>::basic_resolver(boost::asio::io_service*)’
 Connection::Connection(const std::string ip) : m_ip(ip), is_connected(false), m_resolver(tcp::resolver(&m_io_service)), m_query(tcp::resolver::query(m_ip, "connect_back")), m_endpoint_iterator(m_resolver.resolve(m_query)), m_socket(tcp::socket(m_io_service)){
                                                                                                                     ^

I don't understand why, because i use the regular things !

Please help me !
Thanks :)
Last edited on
here's the documentation on the constuctor of ip::basic_resolver:

http://www.boost.org/doc/libs/1_63_0/doc/html/boost_asio/reference.html#boost_asio.reference.ip__basic_resolver.basic_resolver

As the compiler said, it does not take a pointer to io_service. It takes a reference, which could be used as tcp::resolver(m_io_service)
Last edited on
Topic archived. No new replies allowed.