My advice on implementing stuff in C:
My advice on implementing stuff in C:
Posted Oct 18, 2010 0:10 UTC (Mon) by HelloWorld (guest, #56129)In reply to: My advice on implementing stuff in C: by mjthayer
Parent article: Russell: On C Library Implementation
I'm wondering if I understood dskoll correctly,I don't think so. I think that dskoll was talking about virtual inheritance. Say, you have code such as this:
struct A { int a; };
struct D1 : A { int d1; };
struct D2 : A { int d2; };
struct B : D1, D2 { int b; };
Then, B will inherit A::a twice, once from D1 and once from D2. So, inside B, you'll actually have two fields named a, and if you want to use one of them, you always have to use full qualification, that is, you have to write D1::a or D2::a instead of just plain a.
Virtual inheritance solves this problem. If you change the code as follows,
struct A { int a; };
struct D1 : virtual A { int d1; };
struct D2 : virtual A { int d2; };
struct B : D1, D2 { int b; };
then the two A sub-objects in B will be collapsed to a single one. It's also explained in the C++ FAQ lite:
http://www.parashift.com/c++-faq-lite/multiple-inheritance.html
