Is it possible to declare classes and define them later?
Such as for this code
Code:class foo { bar b; }; class bar { foo f; };
Is it possible to declare classes and define them later?
Such as for this code
Code:class foo { bar b; }; class bar { foo f; };
that's called forward declaration.
Code:class foo; class bar { foo *f; };
This example will not work, because foo contains bar, bar contains foo that contains bar that contains foo that contains bar - it will go on forever - the compiler can't deal with that (nor can I, really - I don't quite know when to stop repeating it).
You can have a reference or pointer to one of the classes in the other, but you can't mutually put the entire class inside another class that wholly contains the previous class - it's never going to resolve the content of the class.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Forward declaration may help:
I would ask that you carefully consider foo's and bar's relationship though, to avoid a circular logic problem. Does one control or own another object, for instance? You will want to seek another type of member storage, so that foo can be created without immediately instantiating a bar, which needs a foo, which needs a bar, which needs a foo ...Code:class bar; class foo { bar b; }; class bar { foo f; // whatever };
Code://Forward declaration class bar; class foo { bar* b; } class bar { foo* f; }