C++ multiple inheritance of the same name hidden instance details

  • 2020-04-01 21:25:07
  • OfStack

If part or all of a derived class's direct base class is derived from another common base class,
Members inherited from a higher base class have the same name, so the same name occurs in a derived class. Members of this type with the same name are also uniquely identified using scope discriminators and must be qualified using direct base classes.
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

# include < Iostream>
Using namespace STD.
The class B0
{
Public:
Int nV;
Void fun () {cout< <" Member of B0 "< < Endl; }
};
The class B1: public B0
{
Public:
Int nV1;
};
The class B2: public B0
{
Public:
Int nV2;
};
The class D1: public B1, public B2
{
Public:
Int nVd.
Void fun () {cout< <" Member of D1 "< < Endl; }
};


Int main(int argc, char** argv) {
D1 D1;
D1. B1: : nV = 2;
D1. B1: : fun ();
D1. B2: : nV = 3;
D1. B2: : fun ();
Return 0;
}

Related articles: