Difference in multiple inheritance and multilevel inheritance: same method name ambiguity problem

Hi,

In multi-level inheritance:

class A { 
public:
   void fun() { cout << "A" << endl; }
};

class B : public A {
public:
   void fun() { cout << "A" << endl; }
};

class C : public B { };

int main() {
    C c;
    c.fun();  // Ans: A
}

In multiple inheritance:

class A {
public:
   void fun() { cout << "A" << endl; }
};

class B {
public:
   void fun() { cout << "B" << endl; }
};

class C : public A, public B { /* public: using B::fun; */ };

int main() {
    C c;
    c.fun(); // Error: request for member function is ambiguous // use:  c.A::fun();
} 

I would like to know, why there is no ambiguous problem in the multi-level inheritance code (1st code) which is compiling and giving output perfectly when both the base classes are having the same function signature. Where as it is giving error in the multiple inheritance code (2nd code).

Well, the compiler does not have a precedence for duplicate names for multiple inheritance. If the gods declared that leftmost inheritance has precedence, the compiler could default to A, or vice versa for rightmost. Until then, the compiler makes you be specific.

Multilevel allows redefinition, last wins precedence, but your example had the same fun() definition, for A, at both levels. Typo?