I have to write a code containing 2 classes and one of them depend on the other Please see the image(just to simplify) if you can help me?
I cannot put the image
I have to write a code containing 2 classes and one of them depend on the other Please see the image(just to simplify) if you can help me?
I cannot put the image
In c++ you cannot create two classes A and B, where A will have member variable of B and B will have member variable of A. This is because the sizes must be known in time of parsing the member by the compiler. If you think about it, this structure will be infinite size:
A will have B will have A will have B will have A ....
That is why it cannot be done.
You can only have pointers as variables. This is because, pointer is in the end, just memory address and nothing more, and memory address is always known (4, or 8 bytes).
A will have B* and that is all.
B will have A* and that is all.
To achieve that you can do forward declaration for example.