I want to bind an overloaded function to make an std::future
zmqpp::socket::connect
is created like that:
void connect (endpoint_t const &endpoint)
The first thing i did was that:
auto binded_connect = std::bind(&zmqpp::socket::connect, socket, endpoint);
But that was bad because zmqpp::socket::connect
is an overloaded function.
So I casted the connect function.
auto binded_connect = std::bind(static_cast<void(zmqpp::socket::*)(zmqpp::endpoint_t const&)>(&zmqpp::socket::connect), socket, endpoint);
The thing is g++ don't like that.
He says a lot of things about tuple but i think the most important is :
/usr/include/c++/8/functional:467:70: error: no matching function for call to ‘std::tuple<zmqpp::socket, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::tuple(zmqpp::socket&, const std::__cxx11::basic_string<char>&)’
So I don't really know what to do right now, I have no ideas where search to find answer.
I'm also sorry for bad english, not main language.
Thanks in advice.
Because connect
is member method of socket
class you need to pass socket
object by pointer or reference:
when invoking a pointer to non-static member function or pointer to non-static data member, the first argument has to be a reference or pointer to an object whose member will be accessed: -> more here
auto binded_connect = std::bind(static_cast<void(zmqpp::socket::*)(zmqpp::endpoint_t const&)>(&zmqpp::socket::connect),
&socket, endpoint);
^^^^^^^^
or
auto binded_connect = std::bind(static_cast<void(zmqpp::socket::*)(zmqpp::endpoint_t const&)>(&zmqpp::socket::connect),
std::ref(socket), endpoint);
^^^^^^^^^^^^^^^^