Zal wel iets stoms zijn, maar ik zie even niet waarom dit niet werkt:
Error:
C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| #include <boost/function.hpp> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> class A : public boost::enable_shared_from_this<A> { public: typedef boost::shared_ptr<A> Ptr; typedef boost::function<void (Ptr)> Handler; A(Handler h) : m_h(h) {} ~A() {} void foo() { m_h(shared_from_this()); } Handler m_h; }; class B { public: B() {} ~B() {} void handler(A::Ptr aptr) { } void bar() { // Volgende regel triggered de error A::Ptr a(new A(boost::bind(&B::handler, this))); a->foo(); } }; int main() { B b; b.bar(); return 0; } |
Error:
code:
1
2
3
4
5
6
7
8
9
10
11
| g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"test.d" -MT"test.d" -o"test.o" "../test.cpp" /usr/include/boost/mem_fn.hpp: In member function ‘R& boost::_mfi::dm<R, T>::operator()(T*) const [with R = void ()(boost::shared_ptr<A>), T = B]’: /usr/include/boost/bind.hpp:222: instantiated from ‘R boost::_bi::list1<A1>::operator()(boost::_bi::type<R>, F&, A&, long int) [with R = void (&)(boost::shared_ptr<A>), F = boost::_mfi::dm<void ()(boost::shared_ptr<A>), B>, A = boost::_bi::list1<boost::shared_ptr<A>&>, A1 = boost::_bi::value<B*>]’ /usr/include/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 = boost::shared_ptr<A>, R = void (&)(boost::shared_ptr<A>), F = boost::_mfi::dm<void ()(boost::shared_ptr<A>), B>, L = boost::_bi::list1<boost::_bi::value<B*> >]’ /usr/include/boost/function/function_template.hpp:152: instantiated from ‘static void boost::detail::function::void_function_obj_invoker1<FunctionObj, R, T0>::invoke(boost::detail::function::function_buffer&, T0) [with FunctionObj = boost::_bi::bind_t<void (&)(boost::shared_ptr<A>), boost::_mfi::dm<void ()(boost::shared_ptr<A>), B>, boost::_bi::list1<boost::_bi::value<B*> > >, R = void, T0 = boost::shared_ptr<A>]’ /usr/include/boost/function/function_template.hpp:904: instantiated from ‘void boost::function1<R, T1>::assign_to(Functor) [with Functor = boost::_bi::bind_t<void (&)(boost::shared_ptr<A>), boost::_mfi::dm<void ()(boost::shared_ptr<A>), B>, boost::_bi::list1<boost::_bi::value<B*> > >, R = void, T0 = boost::shared_ptr<A>]’ /usr/include/boost/function/function_template.hpp:720: instantiated from ‘boost::function1<R, T1>::function1(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void (&)(boost::shared_ptr<A>), boost::_mfi::dm<void ()(boost::shared_ptr<A>), B>, boost::_bi::list1<boost::_bi::value<B*> > >, R = void, T0 = boost::shared_ptr<A>]’ /usr/include/boost/function/function_template.hpp:1040: instantiated from ‘boost::function<R ()(T0)>::function(Functor, typename boost::enable_if_c<boost::type_traits::ice_not<boost::is_integral<Functor>::value>::value, int>::type) [with Functor = boost::_bi::bind_t<void (&)(boost::shared_ptr<A>), boost::_mfi::dm<void ()(boost::shared_ptr<A>), B>, boost::_bi::list1<boost::_bi::value<B*> > >, R = void, T0 = boost::shared_ptr<A>]’ ../test.cpp:31: instantiated from here /usr/include/boost/mem_fn.hpp:342: error: invalid use of non-static member function make: *** [test.o] Error 1 |