Boost :: bind 'Call for empty boost :: function' fails if not set in constructor

Why use the following failure if not called by the constructor of the class?

updateState = boost::bind( &PhysicsObject::updateActive, this ); 

However, when executed at runtime, the following happens: with a call to 'what (): to empty exception :: function' exception

 void PhysicsObject::setState( PhsyicsObjectState aState ) { _state = aState; if( _state == ACTIVE ) { // This branch is executed updateState = boost::bind( &PhysicsObject::updateActive, this ); } else { updateState = boost::bind( &PhysicsObject::updateExploding, *this ); } } 
0
source share
1 answer

A call to boost::function that has not been set will throw such an exception. You must initialize it in your constructor according to the standard "state", otherwise your setState will not set it if it setState state similar to the current one.

Note that in the second bind, you pass a copy of the object that this points to.

+2
source

All Articles