Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What is Multiple Inheritance in C++ ?

Inheritance
0
Posted

What is Multiple Inheritance in C++ ?

0
10

It is possible for a derived class to inherit more than a single base class. This is referred as multiple inheritance. The class inherits from multiple base classes where these classes are comma separated. Each listed base class must specify its own access level. E.g. class base1 { }; class base2 { }; class derived: public base1, public base2 { }; The base class constructors are invoked in the declaration order within the class derivation list. In the above example the constructor for base1 will be called first followed by the base2 constructor. Similarly the order of destructor is reverse of the constructor order. If a class inherits from one or more base classes which themselves inherit from a common base class then it can lead to problems. In such case one should use virtual inheritance. Under virtual inheritance only a single shared base class object is inherited regardless of how many times the base class occurs in the derivation hierarchy. E.g.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.