"Phil Nash"
[Edward Diener]
Is there any way to use boost::function and member function pointers with VC6 . I realize it is deficient in partial specialization but I was still hoping to be able to use it. All my attempts to compile meet with failure although the compiler tests say that VC6 succeeds both with boost::function and boost::bind.
It works for me :-)
If I try the bind1st.cpp example in libs\function\example directory I get the error:
error C2784: 'class std::mem_fun_t<_R,_Ty> __cdecl std::mem_fun(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '<Unknown>' from 'int (__thiscall X::*)(int)'
If I try some code of my own and use boost::bind instead, I get an error:
error C2780: 'class boost::_bi::bind_t
,class boost::_bi::list9 __cdecl boost::bind(R (__thiscall T::*)(B1,B2 ,B3,B4,B5,B6,B7,B8) const,A1,A2,A3,A4,A5,A6,A7,A8,A9)' : expects 10 arguments - 2 provided
Amazing. I was struggling with both these very same compiler errors only this morning. Finally I realised I had left something out! Lets have a look at your code and see if you have done the same...
My own code is:
#include "stdafx.h" #include
#include class MyClass { public: int MyMember(int,int,int); };
int MyClass::MyMember(int x,int y,int z) { int a = x + y + z; }
int main(int argc, char* argv[]) { MyClass mcl; boost::function3
bf; bf = boost::bind(&MyClass::MyMember,&mcl); bf(2,3,4); return 0; } Yep, there it is... you need to tell bind the ordinal positions of each argument to bind to. Just rewrite the line that constructs bind something like this:
bf = boost::bind(&MyClass::MyMember,&mcl, _1, _2, _3);
Thanks, that works. I had assumed that if the ordinal positions are not
supplied, that they would just go in order. Evidently ever parameter not
supplied must be given an ordinal position. That makes sense since bind
needs to know how many parameters there are. The documentation is really
deficient in explaining this.
However it doesn't work in VC6 if I change my member function to have 'void'
return and I change my boost::function signature to
boost::function3