Callbacks (or function pointers) between classes


#21

I’d be very interested to see a simple example of the alternatives.
The example of Lambda functions in the tutorials does not seem to deal with the case of referencing methods from different levels of the component hierarchy.
The code above is working in my design but I’d like to learn more!
Thanks for any comments.


#22
public: A() { Bguy = new B(); Bguy->;setCallBack([this](auto a, auto b){this->someMethod(a, b);}) }

#23

Sometimes, having a singleton class can help simplify things, so you don’t need to pass references down your hierarchy. However, using them in a plugin can cause issues, so be careful in that case. If you’re not writing a plugin, SharedResourcePointer is very useful for this.


#24

Thanks for the replies.
The Lambda function certainly appears more robust and readable, relying on language features rather than some std library behaviour.
Singleton classes and SharedResourcePointer are interesting to know about, thanks again for pointing them out.