DDD
DDD

Reputation: 111

Boost function + boost bind complicated situation

I have member function:

void ClassA::Method(ClassB& inputarg);

and I want to have boost::function :

boost::function< void (ClassB&) > 
            FunctionPointer(
            boost::bind((&ClassA::Method, _1, _2)(ClassC->ClassA_User, boost::ref(SomeStructure.ClassB_User)));

but it doesn't compile, what i do wrong ?

error C2064: term does not evaluate to a function taking 2 arguments error C2780: 'boost::_bi::bind_t<_bi::dm_result::type,boost::_mfi::dm,_bi::list_av_1::type> boost::bind(M T::* ,A1)' : expects 2 arguments - 1 provided 7> c:\git\3rdparty\common\include\boost\bind\bind.hpp(1728) : see declaration of 'boost::bind' error C2780: 'boost::_bi::bind_t,_bi::list_av_9::type> boost::bind(boost::type,R (__thiscall T::* )(B1,B2,B3,B4,B5,B6,B7,B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 11 arguments - 1 provided 7> c:\git\3rdparty\common\include\boost\bind\bind_mf2_cc.hpp(223) : see declaration of 'boost::bind'

and many more similar to last line of output.

Upvotes: 0

Views: 204

Answers (1)

ForEveR
ForEveR

Reputation: 55887

If you want create boost::function<void(B&)>, then use just

FunctionPointer(boost::bind(&ClassA::Method, ClassC->ClassA_User, _1));

call it like FunctionPointer(SomeStructure.ClassB_User);

If you want to pass in bind known instance of B, then type of FunctionPointer should be

boost::function<void()>

and bind should be like this

boost::bind(&ClassA::Method, ClassC->ClassA_User,
boost::ref(SomeStructure.ClassB_User)));

then call it like FunctionPointer();

Upvotes: 1

Related Questions