3

As you know, C++ allows multiple inheritance. But, would it be a good programming approach to use multiple inheritance or it should be avoided?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385
  • 1
    Voted to close as not a real question on the grounds of being too vague. Can you propose a scenario in which you think applying multiple inheritance? – Björn Pollex Jan 25 '11 at 14:22
  • 1
    **It depends.** That's really the best answer anyone can give you, unless you edit your question to be more specific. – Cody Gray - on strike Jan 25 '11 at 14:22
  • 1
    Related: [What is the exact problem with multiple inheritance](http://stackoverflow.com/questions/225929/what-is-the-exact-problem-with-multiple-inheritance) – Sven Marnach Jan 25 '11 at 14:26

1 Answers1

3

In general, it's not needed and can make your code more complex.

But there are cases where it's useful. As long as it's useful and isn't causing your code to become unmanageable, I see no reason to avoid it.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • 6
    yeah ... you managed to answer a extremly broad and generic question with an even more generic answer ... *thumbs up* – smerlin Jan 25 '11 at 14:25
  • 1
    This is basically the only answer that *can* be given. It's no more generic than the question was, and it's completely correct. That's my +1. – Cody Gray - on strike Jan 25 '11 at 14:29
  • 1
    I would have +1'd but I disagree with the first statement. Multiple *implementation* inheritance usually adds complexity, but multiple *interface* inheritance does not. – Billy ONeal Jan 25 '11 at 14:30
  • @Billy: If your reasoning is that multiple implementation inheritance spreads the implementation among multiple classes while multiple interface inheritance does not, then I would agree with that. – Jonathan Wood Jan 26 '11 at 18:08
  • @Jonathan: What I mean is that if you have an abstract "ICloneable" class which is added as a mixin in many places, you've not added any complexity (in fact you've reduced the complexity by making your interfaces more granular). For the difference I mean, consider the `interface` in Java and C# -- specifies an interface to which inheriting classes must conform, but no implementation may be specified. – Billy ONeal Jan 26 '11 at 19:10