next up previous
Next: What is a virtual Up: class and struct Previous: How do I derive

How do I avoid ambiguities with multiple class derivation?

Consider the two following valid examples: the left one if non-ambiguous, the right one is.

struct A                            struct A
{                                   {
  void a() {}                         void a() {}
};                                  };
                                    
struct B: public virtual A          struct B: public A
{                                   {
};                                  };
                                    
struct C: public virtual A          struct C: public A
{                                   {
};                                  };
                                    
struct D: public B, public C        struct D: public B, public C // D has two a
{                                   {
};                                  };
                                
void        function()              void function()
{                                   {
  D        d;                         D        d;
                                
  d.a();                              d.a();    // error, ambiguous
}                                     d.B::a(); // ok
                                      d.C::a(); // ok
                                    }



Alexis Angelidis (PhD) 2005-01-11