Why do Listener callbacks have Broadcaster* not Broadcaster& arguments?


#1

Could anyone kindly explain why Listener callbacks (e.g. Slider::Listener’s methods) take Broadcaster* arguments rather than Broadcaster& arguments?

Does this mean that it is not guaranteed that the Broadcaster outlives the Listener? If that is the case, when implementing the Listener callback functions, must I always check that the Broadcaster* points to a valid object before accessing into it (e.g. Slider->getValue()) and if so, how (given that it’s just a raw pointer)?


#2

Broadcaster* broadcaster;
if( broadcaster != nullptr ) { }

??


#3

Even that wouldn’t save you, because the raw pointer will remain pointing to that adress. If it was freed meanwhile, your (broadcaster!=nullptr) will still evaluate to true.
The concepts to make this safe are:

*Component::SafePointer
*Component::BailoutChecker
*WeakReference< ObjectType, ReferenceCountingType >
*std::weak_ptr< class T >