Multiple Inheritance


  • A class can be derived from more than one base class. This is called multiple inheritance. The syntax is as follows:
    class A { }; 	//Base Class A 
    class B { }; 	// Base Class B
    class C: public A, public B {    };
    
    // C is derived from A and B
  • The base classes from which C is derived are listed following the colon on C's specification separated by commas.
    Click here for Example

    Ambiguity in Multiple Inheritance

  • In multiple Inheritance, when two base class (Say, A & B) have got same functions name (Say, show()) and an object of derived class (Say C, inherited from A & B) calls that function, then compiler shows an error showing ambiguous function call.
  • This error can be corrected by specifying clearly by writing base class name in the calling statement.


Multiple Level of Inheritance << Previous

Next >> Pointer & Dynamic memory

Our aim is to provide information to the knowledge seekers.


comments powered by Disqus






Footer1