C++ Boost::bind: a pointer to a bound function may only be used to call the function -


i like

template<typename instancetype>             void add_test(void (instancetype::* test_method )(void*),  std::tr1::shared_ptr<instancetype> user_test_case)             {                 boost::function<void ()> op;                 op = boost::bind<instancetype>(test_method, *user_test_case); 

but says:

1>d:\boost\boost/bind/mem_fn.hpp(359): error: pointer bound function may used call function 1>          return (t.*f_); 

what wrong here?

  1. the 1st template argument of bind return type. so, should void. or omit it.
  2. boost::function signature doesn't match 1 of bound function. make function<void(void *)>.
  3. the functor create should accept 1 argument, provide appropriate argument placeholder.
  4. finally, can bind shared_ptr, directly.

the bottom line: boost::function<void (void *)> op = boost::bind(test_method, user_test_case, _1);


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -