老师布置的题目
1.定义一个基类 Base,有两个公有成员函数fn1( ),fn2 ( )。
私有派生出Derived类,如何通过Derived 类的对象调用基类的函数fnl() ?
#include<iostream>
using namespace std;
class Base{
public:
// Base(); 这个很有意思,若是使用了,编译出错
Base(){};
void fn1()const{cout<<"调用fn1"<<endl;}
void fn2()const{cout<<"调用fn2"<<endl;}
};
class Derived:private Base{
public:
Derived(){}
void fn11()const{cout<<"调用基类的fn1 ";Base::fn1();}
void fn22()const{cout<<"调用的基类fn2 ";Base::fn2();}
};
int main(){
Derived a;
a.fn11();
return 0;
}