Classes, pointer to itself to access from a child class
I have a main class with some child classes inside, I need to be able to access other child classes from a child one or members from the main class like the dosomething() function in the example.
How could I initialise the child classes when the main class is created passing an argument to each one pointing their parent class?
Thanks in advance
Code:
class subExample {
mainExample *classParent;
int i,j;
int dosomething() {
i = i+j+24;
parent->doAnotherThing();
}
subExample(mainExample *parent) {
classParent = parent;
}
};
class mainExample {
subExample childClass;
int doAnotherThing() {
etc
}
};