RT,有一个 protected 的变量在类 A 里面,现在我想在类 B 里面使用,通过继承可以实现吗?
形式化的,
#include<cstdio>
class A{
protected:
int a=50;
};
class B:public A{
public:
void output(void){
printf("%d",a);
}
};
int main(){
B b;
b.output();
}
已知这段代码编译失败,求问题出在了哪里?
'a' was not declared in this scope
编译报错形状如此