派生类的成员变量(函数)屏蔽基类的同名成员变量(函数)
想调用基类的同名成员变量(函数),需要通过作用域分辨符::
/*
派生类的成员变量(函数)屏蔽基类的同名成员变量(函数)
想调用基类的同名成员变量(函数),需要通过作用域分辨符::
*/
#include <iostream>
using namespace std;
class Base
{
public:
int a;
int b;
void print()
{
cout << "print() for Base" << endl;
}
};
class Drived :public Base
{
public:
int b;
int c;
void print()
{
cout << "print() for Drived" << endl;
}
};
int main()
{
Drived d;
d.a = 1;
d.Base::b = 2;
d.b = 3;
d.c = 4;
d.Base::print();
d.print();
return 0;
}