What is the abandoned multiple inheritance in C++?
This article introduces the knowledge of "what is the abandoned multiple inheritance in C++". Many people will encounter this dilemma in the operation of actual cases. then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
After learning about C++ 's inheritance, have we ever wondered whether a class is allowed to inherit from multiple parent classes? Then in C++, it is supported to write code with multiple inheritance, that is, a subclass can have multiple parent classes. At this time, the subclass has all the member variables of the parent class, the subclass inherits all the member functions of the parent class, and the subclass object can be used as any parent class object. The syntax for multiple inheritance is shown below, which is essentially the same as single inheritance!
Class Derived: public BaseA, public BaseB {/ /...}
Let's take the code as an example to analyze it.
# include using namespace std;class BaseA {int ma;public: BaseA (int a) {ma = a;} int getA () {return ma;}}; class BaseB {int mb;public: BaseB (int b) {mb = b;} int getB () {return mb;}}; class Derived: public BaseA, public BaseB {int mc Public: Derived (int a, int b, int c): BaseA (a), BaseB (b) {mc = c;} int getC () {return mc;} void print () {cout