Let there be some class to which I want to pass an object boost::bind to some method:
class FOO { void f( /*type???*/ boostbind_, int i_) { /* ??? вызов boostbind с параметром i_*/ } }; And there is another class whose method I want to pass:
class BOO { void b() { int i=0; auto t = boost::bind(&BOO::b2, this, _1, _2, i); obj.f(t, i); } void b2(boost::system::error_code, size_t, int); FOO obj; }; How correctly to declare a class method in which boost::bind is transferred and how then to use it?
PS It is understood that the class FOO knows nothing about the class BOO (including its existence)
UPDATE Attempt to do through boost::function produces compilation errors when used with boost::asio::ip::udp::socket::async_receive_from(...) . Sample code (to compile to initialize (which takes a lot of additional code) the socket is not necessary):
class FOO { public: void f(boost::function<void(boost::system::error_code ec_, size_t size_, int i_)> boostbind_) { s->async_receive_from( boost::asio::buffer(buffer, 2048), endPoint, boostbind_); } char buffer[2048]; boost::asio::ip::udp::endpoint endPoint; shared_ptr<boost::asio::ip::udp::socket> s; }; class BOO { public: void b() { int i = 99; obj.f(boost::bind(&BOO::b2, this, _1, _2, i)); } void b2(boost::system::error_code ec_, size_t size_, int i_) { std::cout << "\nb2"; } FOO obj; }; int main() { BOO a; ab(); system("pause"); return 0; } Compilation errors:
Error 1 error C2338: ReadHandler type requirements not met c: \ libs \ boost \ boost \ asio \ basic_datagram_socket.hpp 893 1 Test
Error 2 error C2064: c. \ Libs \ boost \ boost \ asio \ basic_datagram_socket.hpp 893 1 Test