Why might using the following fail unless called from the constructor of the class?
updateState = boost::bind( &PhysicsObject::updateActive, this );
However the following fails at runtime, with a ‘what(): call to empty boost::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 );
}
}
Calling a
boost::functionthat wasn’t set would raise such exception. You should initialize it in your constructor according to the default “state”, otherwise yoursetStatewon’t set it if passed a state same as the current.Note that in your second bind, you are passing a copy of the object pointed by
this.