Boost logo

Boost Users :

From: Sean Rhea (srhea_at_[hidden])
Date: 2006-02-13 17:54:12


Hello,

Can someone please tell me why this doesn't work?

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

using namespace std;
using namespace boost;

struct MyClass {
     int i;
     void foo(int j){
         printf("%d, %d\n", i, j);
     }
     function<void(int)> bar() {
         return bind<void>(&MyClass::foo, this);
     }
};

$ g++ -c -g -I/usr/local/include/boost-1_33_1 -I.. foo.cpp
/usr/local/include/boost-1_33_1/boost/mem_fn.hpp: In member function
'R& boost::_mfi::dm<R, T>::operator()(T*) const [with R = void ()
(int), T = MyClass]':
/usr/local/include/boost-1_33_1/boost/bind.hpp:229: instantiated
from 'void boost::_bi::list1<A1>::operator()(boost::_bi::type<void>,
F&, A&, int) [with F = void (MyClass::*)(int), A =
boost::_bi::list1<int&>, A1 = boost::_bi::value<MyClass*>]'
/usr/local/include/boost-1_33_1/boost/bind/bind_template.hpp:32:
instantiated from 'typename boost::_bi::result_traits<R, F>::type
boost::_bi::bind_t<R, F, L>::operator()(A1&) [with A1 = int, R =
void, F = void (MyClass::*)(int), L =
boost::_bi::list1<boost::_bi::value<MyClass*> >]'
/usr/local/include/boost-1_33_1/boost/function/function_template.hpp:
136: instantiated from 'static void
boost::detail::function::void_function_obj_invoker1<FunctionObj, R,
T0>::invoke(boost::detail::function::any_pointer, T0) [with
FunctionObj = boost::_bi::bind_t<void, void (MyClass::*)(int),
boost::_bi::list1<boost::_bi::value<MyClass*> > >, R = void, T0 = int]'
/usr/local/include/boost-1_33_1/boost/function/function_template.hpp:
479: instantiated from 'void boost::function1<R, T0,
Allocator>::assign_to(FunctionObj,
boost::detail::function::function_obj_tag) [with FunctionObj =
boost::_bi::bind_t<void, void (MyClass::*)(int),
boost::_bi::list1<boost::_bi::value<MyClass*> > >, R = void, T0 =
int, Allocator = std::allocator<void>]'
/usr/local/include/boost-1_33_1/boost/function/function_template.hpp:
430: instantiated from 'void boost::function1<R, T0,
Allocator>::assign_to(Functor) [with Functor =
boost::_bi::bind_t<void, void (MyClass::*)(int),
boost::_bi::list1<boost::_bi::value<MyClass*> > >, R = void, T0 =
int, Allocator = std::allocator<void>]'
/usr/local/include/boost-1_33_1/boost/function/function_template.hpp:
294: instantiated from 'boost::function1<R, T0,
Allocator>::function1(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functo
r>::value>::value, int>::type) [with Functor =
boost::_bi::bind_t<void, void (MyClass::*)(int),
boost::_bi::list1<boost::_bi::value<MyClass*> > >, R = void, T0 =
int, Allocator = std::allocator<void>]'
/usr/local/include/boost-1_33_1/boost/function/function_template.hpp:
637: instantiated from 'boost::function<R ()(T0),
Allocator>::function(Functor, typename
boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functo
r>::value>::value, int>::type) [with Functor =
boost::_bi::bind_t<void, void (MyClass::*)(int),
boost::_bi::list1<boost::_bi::value<MyClass*> > >, R = void, T0 =
int, Allocator = std::allocator<void>]'
foo.cpp:15: instantiated from here
/usr/local/include/boost-1_33_1/boost/mem_fn.hpp:347: error: invalid
use of non-static member function

Thanks,
Sean

-- 
        Compassion, tolerance, consideration of others, the responsible
           use of knowledge and power. These principles transcend the
          barriers between religious believers and non-believers; they
                  belong not to one faith, but to all faiths.
                             -- The 14th Dalai Lama



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