5 ms·
C++noob here, but: Given that the members in your example are no pointers but actual substructures within your data structure, wouldn't that result in an infini
by xg15 11y ago
C++noob here, but: Given that the members in your example are no pointers but actual substructures within your data structure, wouldn't that result in an infinite data structure? Therefore it sewms quite logical to me it's not allowed.
Disallowing cyclical dependencies via pointer would make no sense though.
- humanrebar 11y agoRight. C++ objects are values, not references to values like in almost all other languages. So C++ needs to know the sizes of everything to construct them. If you tried to write out the mathematical series describing the ultimate size you would need to allocate for A or B, you would end up with a value approaching infinity.
- TheCoelacanth 11y agoThis is probably my favorite thing about C++. Values are so much easier to reason about than references.
- Ygg2 11y agoIt's more of a simplification. Although, I did try references and they didn't compile either. In fact, if I remember correctly the error was "forward declaration forbidden". After spending about 10-12 years away from C++, I was pretty much on novice level. I remember some things, but most details and day to day specifics are gone. It did serve as a fresh reminder why I hate C++. Or more precisely, why I hate C++ compilers.