Boost logo

Boost Users :

From: Phil Nash (phil.nash.lists_at_[hidden])
Date: 2002-07-13 10:33:23


[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<R,class
> boost::_mfi::cmf8<R,T,B1,B2,B3,B4,B5,B6,B7,B8>,class
boost::_bi::list9<class
> boost::_bi::value<R>,class boost::_bi
> ::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>,class
> boost::_bi::value<R>,class boost::_bi::value<R>,class
> boost::_bi::value<R>,class boost::_bi::value<R>,class boost::_bi::value<R>
>
> > __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 <boost\function.hpp>
> #include <boost\bind.hpp>
>
> 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<int,int,int,int> 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);

...and it should work. I have not tried to compile the above since I am not
on my development machine at the moment, but I'm fairly confident that
should do it (or at least point you in the right direction).

Regards,

[)o
IhIL..


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