父类和子类具有同名的成员变量:
子类访问父类的属性 子类.父类::成员变量名 来调用父类的成员变量(作用域)
(成员函数同理)
#include<iostream>
#include<cstdio>
using namespace std;
class A{
public:
int _c = 10;
};
class B: public A{ // 除了私有内容无法访问 其他内容访问权限不变
public:
int _c = 11;
};
void f(){
B b = B();
cout<<b._c<<endl;
cout<<b.A::_c<<endl;
}
int main(){
f();
return 0;
}