Boost logo

Boost Users :

From: Edward Diener (eddielee_at_[hidden])
Date: 2002-07-13 13:50:35


"Phil Nash" <phil.nash.lists_at_[hidden]> wrote in message
news:002c01c22a82$a136e680$b869883e_at_TimeMachine...
> [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);

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<void,int,int,int> bf; . Now I get:

error C2562: '()' : 'void' function returning a value etc. What a PITA !

Furthermore I still don't know why the bind1st.cpp example doesn't work in
VC6 but I can ignore that since boost::bind si so much better. However
changing my design so that the member function callback has a non-void
return value is not optimal.


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