Boost logo

Boost Users :

Subject: [Boost-users] [bind, function] pointer to member function under Xcode 4.1.1
From: Stuart Malone (samalone_at_[hidden])
Date: 2012-08-13 14:35:54


I'm having trouble compiling some very simple boost::function and boost::bind code under Xcode 4.4.1 using the default Apple LLVM compiler 4.0. I've simplified the code down to:

#include <boost/bind.hpp>
#include <boost/function.hpp>

struct Monitor {
    void Change(int a, int b);
    
    void Lose() {
        auto b = boost::bind(&Monitor::Change, this);
        boost::function<void (int, int)> f(b);
    }
};

On the second line of the Lose() function I get the error "reference to non-static member function must be called". The full error message is below.

I haven't been able to figure out just where the problem is. Is this an incompatibility between Boost 1.50 and Xcode 4.4.1, or am I making some other mistake? Is there a straightforward workaround?

Thanks,

—Stuart

In file included from /Users/samalone/Projects/functionbind/functionbind/main.cpp:1:
In file included from /Users/samalone/Boost/boost/bind.hpp:22:
In file included from /Users/samalone/Boost/boost/bind/bind.hpp:26:
In file included from /Users/samalone/Boost/boost/mem_fn.hpp:22:
/Users/samalone/Boost/boost/bind/mem_fn.hpp:342:16: error: reference to non-static member function must be called
        return (p->*f_);
               ^~~~~~~~
/Users/samalone/Boost/boost/bind/bind.hpp:243:16: note: in instantiation of member function 'boost::_mfi::dm<void (int, int), Monitor>::operator()' requested here
        return unwrapper<F>::unwrap(f, 0)(a[base_type::a1_]);
               ^
/Users/samalone/Boost/boost/bind/bind_template.hpp:61:27: note: in instantiation of function template specialization 'boost::_bi::list1<boost::_bi::value<Monitor *> >::operator()<void (&)(int, int), boost::_mfi::dm<void (int, int), Monitor>, boost::_bi::list2<int &, int &> >' requested here
        BOOST_BIND_RETURN l_(type<result_type>(), f_, a, 0);
                          ^
/Users/samalone/Boost/boost/function/function_template.hpp:153:33: note: in instantiation of function template specialization 'boost::_bi::bind_t<void (&)(int, int), boost::_mfi::dm<void (int, int), Monitor>, boost::_bi::list1<boost::_bi::value<Monitor *>> >::operator()<int, int>' requested here
          BOOST_FUNCTION_RETURN((*f)(BOOST_FUNCTION_ARGS));
                                ^
/Users/samalone/Boost/boost/function/function_template.hpp:75:36: note: expanded from macro 'BOOST_FUNCTION_RETURN'
# define BOOST_FUNCTION_RETURN(X) X
                                   ^
/Users/samalone/Boost/boost/function/function_template.hpp:907:53: note: in instantiation of member function 'boost::detail::function::void_function_obj_invoker2<boost::_bi::bind_t<void (&)(int, int), boost::_mfi::dm<void (int, int), Monitor>, boost::_bi::list1<boost::_bi::value<Monitor *>>>, void, int, int>::invoke' requested here
        { { &manager_type::manage }, &invoker_type::invoke };
                                                    ^
/Users/samalone/Boost/boost/function/function_template.hpp:722:13: note: in instantiation of function template specialization 'boost::function2<void, int, int>::assign_to<boost::_bi::bind_t<void (&)(int, int), boost::_mfi::dm<void (int, int), Monitor>, boost::_bi::list1<boost::_bi::value<Monitor *>>> >' requested here
      this->assign_to(f);
            ^
/Users/samalone/Boost/boost/function/function_template.hpp:1042:5: note: in instantiation of function template specialization 'boost::function2<void, int, int>::function2<boost::_bi::bind_t<void (&)(int, int), boost::_mfi::dm<void (int, int), Monitor>, boost::_bi::list1<boost::_bi::value<Monitor *>>> >' requested here
    base_type(f)
    ^
/Users/samalone/Projects/functionbind/functionbind/main.cpp:9:42: note: in instantiation of function template specialization 'boost::function<void (int, int)>::function<boost::_bi::bind_t<void (&)(int, int), boost::_mfi::dm<void (int, int), Monitor>, boost::_bi::list1<boost::_bi::value<Monitor *>>> >' requested here
        boost::function<void (int, int)> f(b);
                                         ^
1 error generated.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net