What is Multiple Inheritance in C++ ?
It is possible for a derived class to inherit more than a single base class. This is referred as multiple inheritance. The class inherits from multiple base classes where these classes are comma separated. Each listed base class must specify its own access level. E.g. class base1 { }; class base2 { }; class derived: public base1, public base2 { }; The base class constructors are invoked in the declaration order within the class derivation list. In the above example the constructor for base1 will be called first followed by the base2 constructor. Similarly the order of destructor is reverse of the constructor order. If a class inherits from one or more base classes which themselves inherit from a common base class then it can lead to problems. In such case one should use virtual inheritance. Under virtual inheritance only a single shared base class object is inherited regardless of how many times the base class occurs in the derivation hierarchy. E.g.
Related Questions
- If the husband dyes leaving children and wife and wife remarried can she still have a part in the inheritance of her late husband house?
- I have heard that a Living (inter vivos) Trust is a good way to avoid the costs of probate and inheritance taxes. Is it a good idea?
- What is the mode of inheritance for hip dysplasia?