13

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?

4
  • 1
    The language standard probably stipulates a lower bound. But is this really going to be an issue in practice? Dec 5, 2013 at 16:28
  • 2
    Chances are very high that if you are inheriting from more than 1 non-abstract base class, you have a severe design problem. Dec 5, 2013 at 16:28
  • 2
    Its not about a design flaw or a case of judgement. I don't even work with C++. A curious kid happens to ask me this and I don't really have an answer. So somebody tell me..
    – Tom Thomas
    Dec 5, 2013 at 16:30
  • 1
    There is what the standard allows (both Mat and M.M. have stated that), but then there is what is practical. Multiple inheritance of non-abstract base classes is messy, and 95% of the time should be avoided. Dec 5, 2013 at 16:40

2 Answers 2

16

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.

2
5

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.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.