Boost logo

Boost :

From: Robert Dailey (rcdailey_at_[hidden])
Date: 2008-03-13 15:35:33

On Thu, Mar 13, 2008 at 2:11 PM, Robert Dailey <rcdailey_at_[hidden]> wrote:
> I was actually able to get this working, surprisingly enough. I copied
> over function_types into boost 1.34.1 and at the very least bind_mem_fn
> seems to work.
> However, I'm having a bit of an issue with my design that uses
> bind_mem_fn. Right now I have a class that has a boost::tuple of objects
> which, on construction, bind a function to a boost::signal. In my
> constructor, I fill the tuple with various references to member functions of
> the class initializing the tuple. For example:
> using boost::dataflow::utility::bind_mem_fn;
> Rocket_Input::Rocket_Input()
> : m_subscriptions( bind_mem_fn( &Rocket_Input::HandleKey, this ),
> bind_mem_fn( &Rocket_Input::HandleMouseMotion,
> this ),
> bind_mem_fn( &Rocket_Input::HandleMouseWheel, this
> ),
> bind_mem_fn( &Rocket_Input::HandleMouseButton,
> this )
> )
> {}
> While this does compile, it will crash any time that one of the function
> objects is called because in the initializer list, 'this' references a NULL
> pointer when the class object was allocated on the heap via a call to 'new'.
> Is there a way I can initialize my tuple so that 'this' will be a valid
> pointer? For now, I might just go ahead and make my m_subscriptions tuple a
> boost::scoped_ptr and initialize it in the constructor body and see if that
> helps.
> Thanks.

Never mind, I figured it out. Simply dereference 'this' before passing it
into bind_mem_fn() and that seems to fix the issue.

Boost list run by bdawes at, gregod at, cpdaniel at, john at