Question

I would like to do something 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 it says:

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

What is wrong here?

Was it helpful?

Solution

  1. The 1st template argument of bind is the return type. So, it should be void. Or just omit it.
  2. boost::function signature doesn't match the one of the bound function. Make it function<void(void *)>.
  3. The functor you create should accept 1 argument, so provide the appropriate argument placeholder.
  4. Finally, you can bind to the shared_ptr, directly.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top