c++ - How can boost::bind call private methods? -


boost::bind extremely handy in number of situations. 1 of them dispatch/post method call io_service make call later, when can.

in such situations, boost::bind behaves 1 might candidly expect:

#include <boost/asio.hpp> #include <boost/bind.hpp>  boost::asio::io_service ioservice;  class { public:     a() {                 // ioservice call b, private, how?                 ioservice.post(boost::bind(&a::b, this));             }  private:    void b() {} };  void main() {     a::a();     boost::asio::io_service::work work(ioservice);     ioservice.run(); } 

however, far know boost creates functor (a class operator()()) able call given method on given object. should class have access private b? guess not.

what missing here ?

you can call member function via pointer-to-member-function, regardless of accessibility. if function private, members , friends can create pointer it, can use pointer once created.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -