Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit of multiple inheritance in C++

What is the limit of multiple inheritance in C++? i.e, how many classes can a class inherit from? Is it implementation dependent or is there a constraint placed on the number of classes you can inherit from in multiple inheritance?

like image 466
Tom Thomas Avatar asked Dec 05 '13 16:12

Tom Thomas


People also ask

What are the limitations of multiple inheritance?

The disadvantage of multiple inheritance is that it can lead to a lot of confusion when two base classes implement a method with the same name.

Does C allow multiple inheritance?

Master C and Embedded C Programming- Learn as you go So the class can inherit features from multiple base classes using multiple inheritance. This is an important feature of object oriented programming languages such as C++.

Why is multiple inheritance not allowed?

Java doesn't support multiple inheritances in classes because it can lead to diamond problem and rather than providing some complex way to solve it, there are better ways through which we can achieve the same result as multiple inheritances.

How many parent classes can be in multi level inheritance?

In Multiple Inheritance, each child can be derived from two or more parents. Multilevel inheritance can have multiple levels of inheritance. The base class is the parent of all the classes. Multiple Inheritance has two class levels, i.e., base class (parent class) and derived class (child class).


2 Answers

It's implementation defined. C++11 gives recommended minimums in the Implementation quantities section of the standard:

— Direct and indirect base classes [16 384].
— Direct base classes for a single class [1 024].
[...]
— Direct and indirect virtual bases of a class [1 024].

I'd say that's pretty generous.

like image 50
Mat Avatar answered Sep 23 '22 16:09

Mat


Per §10.1:

1 A class can be derived from any number of base classes. [Note: The use of more than one direct base class is often called multiple inheritance. —end note ]

Everything else depends on compiler's implementation and limitations.

like image 23
masoud Avatar answered Sep 24 '22 16:09

masoud