When should you use multiple inheritance?

Answer Posted / munendra kumar

There are three acceptable answers: "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way."

There are some famous C++ pundits and luminaries who disagree with that third answer, but I will accept it.

Let's digress to consider this issue lest your interview turn into a religious debate. Consider an Asset class, Building class, Vehicle class, and CompanyCar class. All company cars are vehicles. Some company cars are assets because the organizations own them. Others might be leased. Not all assets are vehicles. Money accounts are assets. Real estate holdings are assets. Some real estate holdings are buildings. Not all buildings are assets. Ad infinitum. When you diagram these relationships, it becomes apparent that multiple inheritance is a likely and intuitive way to model this common problem domain. The applicant should understand, however, that multiple inheritance, like a chainsaw, is a useful tool that has its perils, needs respect, and is best avoided except when nothing else will do.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why would you use pointers in c++?

623


What is cin clear () in c++?

610


How does code-bloating occur in c++?

751


What are the advantages of c++ over c?

584


What is the most common mistake on c++ and oo projects?

519






What does I ++ mean in c++?

583


How can you differentiate between inheritance and implementation in c++?

640


How do you declare A pointer to a function which receives nothing and returns nothing

719


Which function cannot be overloaded c++?

577


What is a virtual destructor? Explain the use of it?

548


Explain the virtual inheritance in c++.

597


Can I uninstall microsoft c++ redistributable?

606


Why do we need templates?

542


What are vtable and vptr?

618


Write a program to find the reverse Fibonacci series starting from N.

608