[Boost][Bind] How to bind template function member
Hi,
I would like to know how I can use boost::bind with template function
member?
To explain my problem, you will find hereafter an example code that
demonstrates it. In this code, when we try to bind the function member
X::g the compiler failed with tons of error message.
Am I doing something wrong?
Best regards,
Marc Viala
mailto:mviala@acticm.com
-----------------------------------
Platform:
VC++ 7.1
Boost 1.33.1
-----------------------------------
#include
Marc Viala wrote:
Hi,
I would like to know how I can use boost::bind with template function member?
To explain my problem, you will find hereafter an example code that demonstrates it. In this code, when we try to bind the function member X::g the compiler failed with tons of error message.
Am I doing something wrong?
Best regards,
Marc Viala mailto:mviala@acticm.com
----------------------------------- Platform: VC++ 7.1 Boost 1.33.1
----------------------------------- #include
#include struct X { template
void g(A& a, B& b) { std::cout << a << " " << b << '\n' ; } void f(int& i) { std::cout << i << '\n'; } } ;
template
void e(A& a, B& b) { std::cout << a << " " << b << '\n' ; } int main(int argc, char* argv[]) { int a = 10, b = 11 ; X x ; boost::function
pe = boost::bind(&e , a, b) ; // <- OK pe() ; boost::function pg = boost::bind(&X::g , &x, a, b) ; // <- Don't compile?
Try... = boost::bind((void(X::*)(int,int))&X::g,&x,a,b) -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org
Thanks for your help, but...
boost::function
Hi,
I would like to know how I can use boost::bind with template function member?
To explain my problem, you will find hereafter an example code that demonstrates it. In this code, when we try to bind the function member X::g the compiler failed with tons of error message.
Am I doing something wrong?
Best regards,
Marc Viala mailto:mviala@acticm.com
----------------------------------- Platform: VC++ 7.1 Boost 1.33.1
----------------------------------- #include
#include struct X { template
void g(A& a, B& b) { std::cout << a << " " << b << '\n' ; } void f(int& i) { std::cout << i << '\n'; } } ;
template
void e(A& a, B& b) { std::cout << a << " " << b << '\n' ; } int main(int argc, char* argv[]) { int a = 10, b = 11 ; X x ; boost::function
pe = boost::bind(&e , a, b) ; // <- OK pe() ; boost::function pg = boost::bind(&X::g , &x, a, b) ; // <- Don't compile?
Try... = boost::bind((void(X::*)(int,int))&X::g,&x,a,b) -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Marc VIALA wrote:
Thanks for your help, but...
boost::function
pg = boost::bind((void(X::*)(int,int))&X::g, &x, a, b) ; Oups, with the correction same result, compilation failed, but not with the same first message error: " can't convert 'overloaded-function' in 'void (__thiscall X::* )(int,int)' " now?
Oops, I read you example more clearly now. The arg types don't match, it should be a cast to (void (X::*)(int&,int&)).
Could you give some feedbacks about the reason of the compilation failure? Is this due to some restrictions on VC++ 7.1?
I'm not sure where the restriction is, just that it works. I think VC8 handles the specialization syntax correctly. Be gald you are only getting a compile error. I tried doing something slightly more complicated recently and got an ICE with VC71, but not with VC8. Doing the cast gives the compiler the context it needs to decide on which overload to use. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org
Thanks for your help, but...
boost::function
pg = boost::bind((void(X::*)(int,int))&X::g, &x, a, b) ; Oups, with the correction same result, compilation failed, but not with
Thanks a lot... and I'm sorry to have not seen the args mismatch in your first mail. With this explicit cast, the bind function compiles. Thanks for your help. Marc Viala mailto:mviala@acticm.com -----Message d'origine----- De : boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] De la part de Rene Rivera Envoyé : lundi 23 janvier 2006 20:40 À : boost-users@lists.boost.org Objet : Re: [Boost-users] [Boost][Bind] How to bind template function member Marc VIALA wrote: the
same first message error: " can't convert 'overloaded-function' in 'void (__thiscall X::* )(int,int)' " now?
Oops, I read you example more clearly now. The arg types don't match, it should be a cast to (void (X::*)(int&,int&)).
Could you give some feedbacks about the reason of the compilation failure? Is this due to some restrictions on VC++ 7.1?
I'm not sure where the restriction is, just that it works. I think VC8 handles the specialization syntax correctly. Be gald you are only getting a compile error. I tried doing something slightly more complicated recently and got an ICE with VC71, but not with VC8. Doing the cast gives the compiler the context it needs to decide on which overload to use. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - Grafik/jabber.org _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Marc Viala
-
Marc VIALA
-
Rene Rivera