Function Pointers or Delegates
Another C++ noob question here which I would appreciate some input on.
I have the following situation:
I have 2 classes, let's call them The Boss and The Worker.
The Boss creates a new instance of The Worker, and instructs The Worker to start doing its thing. Now when certain conditions are met in The Worker, it needs to post back to The Boss telling it that something's happened.
Now, I'm looking to make The Worker generic, in the sense that when The Boss instructs The Worker to start doing its thing, it must also give it a reference to one of the Boss' functions which must be called when The Worker wants to inform The Boss of something happening.
I've tried getting function pointers as well as delegates working but I'm going on 2 hours here without any results, so any help would be greatly appreciated.
I suppose my question officially is: What approach should I use to solve this, and example code would be greatly appreciated.
asked Apr 09 '14 at 07:43 PM in C++ Programming
Wiki Tutorial on Function Pointers
I wrote an entire tutorial on Function Pointers!
The Code, not as pretty as on wiki
Follow this question
Once you sign in you will be able to subscribe for any updates here