定义基类 Base,有两个共有成员函数 fn1()、fn2(),私有派生出 Derived 类,如果想在 Derived 类的对象中使用基类函数 fn1(),应怎么办?
解:
class Base { public: int fn1() const { return 1; } int fn2() const { return 2; } }; class Derived : private Base { public: int fn1() { return Base::fn1();}; int fn2() { return Base::fn2();}; }; void main() { Derived a; a.fn1(); }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题
解: