top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

When should we use multiple inheritance in C++?

+1 vote
327 views
When should we use multiple inheritance in C++?
posted Dec 16, 2014 by Anwar

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

USE OF MULTIPLE INHERITANCE:

There are three acceptable answers:-

"Never,""Rarely," and "When the problem domain cannot be accurately modeled any other way."
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.

answer Dec 17, 2014 by Mohammed Hussain
...