单选题
有如下程序: #inc1ude <iostream> using namespace std; c1ass Base { private: void funl()const{cout<<"funl";} protected: void fun2()const{cout<<"fun2";} public: void fun3()const{cout<<"fun3";} }; c1ass Derived: protected Base { public: void fun4()const{cout<<"fun4";} }; int main() { Derived obj; obj.funl(); //① obj.fun2(); //② obj .fun3(); //③ obj.fun4(); //④ retum (); } 其中有语法错误的语句是( )。
【正确答案】
B
【答案解析】解析:此题考查的是保护继承。因为Derived以protected方式继承了Base类,所以父类Base中的公有成员和保护成员均成了Derived类的保护成员,而Base类的私有成员Derived类不可访问。所以,主函数中通过Derived类的对象只能够访问到Derived类的公有成员。