C ++ multi-inheritance hidden instances with the same name

Source: Internet
Author: User

If some or all of the direct base classes of a derived class are derived from another common base class, in these Russian base classes,
Members inherited from the base class at the upper level have the same name, so the same name will appear in the derived class. For members with the same name of this type, the scope identifier must also be used for unique identifiers, and the base class must be used for restriction.
--------------------------------------------------
/*
* File: Main. cpp
* Author: Yubao
*
* Created on May 31,200 9, AM
*/
# Include <iostream>
Using namespace STD;
Class B0
{
Public:
Int NV;
Void fun () {cout <"Member of B0" <Endl ;}
};
Class B1: Public B0
{
Public:
Int nv1;
};
Class B2: Public B0
{
Public:
Int nv2;
};
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.