How do I access a base class member when a derived class and a base class member have the same name in CPP? Similar to super in Python

-sharpinclude <iostream>
using namespace std;

class Base
{
    public:
        int a = 10;

        void print()
        {
            cout << "BASE: a=" << a << endl;
        }
};

class Derive:public Base
{
    public:
        int a = 20;
        void print()
        {
            cout << "DERIVE: a=" << a << endl;
            //BASE::a
        }
};

int main()
{
    Base bc;
    Derive dc;

    bc.print();
    dc.print();
    system("PAUSE");
}
CPP
Mar.03,2021

recommended


for public members, this is fine:

-sharpinclude <iostream>
using namespace std;

class Base
{
public:
    int a = 10;

    void print()
    {
        cout << "BASE: a=" << a << endl;
    }
};

class Derive:public Base
{
public:
    int a = 20;
    void print()
    {
        cout << "BASE in DERIVE: a=" << Base::a << endl;
        //BASE::a
    }
};

int main()
{
    Base bc;
    bc.Base::a = 30;
    Derive dc;
    dc.Base::a = 40;
    cout << "DERIVE a = " << dc.a << endl;

    bc.print();
    dc.print();
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52679-44126.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52679-44126.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?