Couldn't the diamond problem be resolved just by using the first inherited declaration found? I mean,
public class A { public virtual int getInt(); }; public class B : public A { public int getInt() {return 6;} }; public class C : public A { public int getInt() {return 7;} }; public class D: public B, public C {};
for class D
, since B
is listed first, couldn't we just by default (when it's ambiguous) use B::getInt()
if D::getInt()
is called? Kind of how the PATH environment variable works in UNIX and other OS's; if two things exist with the same name in different locations in the PATH variable, then the first location shall be used by default (unless otherwise qualified).
Edit: by 'first' inherited declaration found I mean according to simple left-to-right depth-first order
Edit#2: Just updated the above implementation to be more diamond-like.