2 ms·
> Does D get two copies of A's state? It's hard to come up with an intuitive behaviour. C++ gonna C++, which means the language covers all the bases because so
by bitwize 3y ago
> Does D get two copies of A's state? It's hard to come up with an intuitive behaviour.
C++ gonna C++, which means the language covers all the bases because some programmer might get mad if their use case wasn't accounted for.
C++ has something called virtual inheritance, wherein if subclasses B and C inherit virtually from A, any subclasses of both B and C will get one copy of A's state. Otherwise, they will get two copies: one from B and one from C.
This solves the problem of addressing concerns of all programmers w.r.t. the diamond inheritance problem, but makes the language more complex (and triggers my CPPPTSD).
https://en.wikipedia.org/wiki/Virtual_inheritance https://en.wikipedia.org/wiki/Virtual_inheritance
- pfdietz 3y agoIn this vein, note that Common Lisp's inheritance would always be virtual.