选择题
有如下程序:
classBase{
public:
int data:
};
class Derived1:public Base{};
class Derived2:protected Base{};
int main(){
Derived1 d1;
Derived2 d2;
d1.data=0; //①
d2.data=0; //②
return 0;
}
下列关于程序编译结果的描述中,正确的是______。
A、
①②皆无编译错误
B、
①有编译错误,②无编译错误
C、
①无编译错误,②有编译错误
D、
①②皆有编译错误
【正确答案】
C
【答案解析】
保护继承的类Dervied2不能访问基类Base中的公共数据成员data。
提交答案
关闭