Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost:Bind//Boost:Function -- Need some help with a constructor trying to bind to a function
From: Ryan Gallagher (ryan.gallagher_at_[hidden])
Date: 2008-11-02 19:57:02

Charles Milutinovic <kssarh <at>> writes:
> namespace Alpha{ class MethodsInHere{
>      void doesSomething(POD::POD* arg0){}
> };}
> namespace EventHandler{ class EventHandler{
>    public:
>        EventHandler(boost::function<void (POD::POD*)>& function)
> : assign_to_me(function){}
>        boost::function<void (POD::POD*)>& assign_to_me;
>     };}

I don't think you want assign_to_me to be a reference,
but just hold by value. Otherwise you're holding a reference to
a temporary below.

> Alpha::MethodsInHere mih;
> EventHandler eh(boost::bind(&Alpha::MethodsInHere::doesSomething,
> ????, _1))
> --------My question is basically if this is possible. 
> I was having a ton of trouble getting this to work, and after
> digging through some docs it seems like the '?????' in line of
> code in #4 needs to be a reference to eh . . . which isn't
> constructed yet. If I'm wrong, please tell me how to construct
> this bind properly. 

Sorry, but you're wrong. You want "????" to be "mih", not "eh".
"doesSomething"'s type is basically
"(Alpha::MethodsInHere&, POD::POD*) -> void"
hence you need and instance of Alpha::MethodsInHere. HTH,


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at