My question is with regards to callbacks and function pointers, two topics with which I have little experience but am trying to figure out.
Say I have class A , B and C
each class has a method Run()
classes B and C each contain and instance of A.
classes B and C do not derive from a common base class (while that might simplify things via polymorphism and virtual functions, it would not be appropriate from a modelling standpoint)
when A:Run() is invoked, it needs to to execute B:Run() or A:Run() depending on which class, A or B, is the container.
(I know, this isn't the best OO design, contained classes shouldn't need to know of whom contains them)
Anyway - if C were not in the picture, I could just do this in A:
But since there are two discrete types of classes (in this example) I can't just store a member pointer to the container object because I don't know of which type it should be defined as.
Isn't this kinda what function pointers are for? when B instantiates its contained instance of A, is there a way for B to tell A - "MY Run() method is what you will execute when your Run() is invoked, here is the address to it so you don't need to know if I am B or C" ?
If that is possible, how would I go about doing it?