How can two struct/classes refer to each other?
This problem takes many different flavors, but the general issues goes like this: struct xyz { struct abc Abc; // AA }; struct abc { struct xyz Xyz; // BB }; Unfortunately, for this to work, struct abc needs to be moved before xyz, or else, how could line AA work? But wait! That would mean xyz needs to be moved before abc making this circular. One way around this is: struct abc; // CC struct xyz { struct abc* Abc; // DD }; struct abc { struct xyz* Xyz; // EE }; Here, we’ve changed Abc and Xyz into pointers. As well, we’ve forward declared abc in line CC. Therefore, even though abc has still not been defined, only declared, that enough to satisfy the pointers, because there is not yet any code which is going to be dereferencing the pointers, and by the time there is, both struct will have been defined. Of course this new design implies having to dynamically allocate the memory these pointers will point to… unless of course, the self references are through C++ references, which are pos