(Note: this is a ridiculously theoretical discussion that might be complete clap-trap. Not responsible for any brain damage resulting from reading it.)
Quote:Original post by phresnel
Quote:Original post by NotAYakk
Quote:Original post by SiCrane
That can't work. If an A contains a B and a B contains an A, then an A would have to contain an A by value, which means that A would need to be infinitely large.
Or zero in size! (yes yes, that is a purely theoretical snark that doesn't apply in this situation)
Not blessed by standards, I think.
So the idea would be something like this:
struct A { B b;};struct B { A a;};
Both A and B would have size 1. (void*)&(b.a) == (void*)B(b) == (void*)&(a.b) == (void*)&(a.b.a.b.a.b.a.b.a.b).
So, assuming the rule that you need a complete class to instantiate an instance of a class was eliminated... would the above be legal?
sizeof(A) == sizeof(B) == 1.
sizeof(A) == sum(sizeof(contents of A)).
It passes the various POD tests (memory layout is indeed consistent). In fact, the POD test demands that &(a.b.a) == &(a) (or, more specifically:
A a;
B* b = reinterpret_cast<B*>(&a);
A* a2 = reinterpret_cast<A*>(b);
then:
a2 == &a
is true.
I'm not sure how this would actually be useful (if it was allowed). You could use it as a form of infinite type loop? Where each recursive function's call's choice is moderated by the type of a passed in substructure.
It is definitely pathological.