Boost logo

Boost Users :

From: Rene Rivera (grafik.list_at_[hidden])
Date: 2006-01-23 11:12:00


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_at_[hidden]
>
> -----------------------------------
> Platform:
> VC++ 7.1
> Boost 1.33.1
>
> -----------------------------------
> #include <boost/bind.hpp>
> #include <boost/function.hpp>
>
> struct X {
> template<typename A, typename B>
> void g(A& a, B& b)
> { std::cout << a << " " << b << '\n' ; }
>
> void
> f(int& i)
> { std::cout << i << '\n'; }
> } ;
>
> template<typename A, typename B>
> 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<void (void)> pe = boost::bind(&e<int,int>, a, b) ;
> // <- OK
> pe() ;
> boost::function<void (void)> pg = boost::bind(&X::g<int,int>, &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 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