定义一个基类Base,有两个公有成员函数fn1,fn2,私有派生出Derived类,如何通过Derived类的对象调用基类的函数fn1。

发布时间 2023-04-10 19:51:28作者: 笠大

定义一个基类Base,有两个公有成员函数fn1,fn2,私有派生出Derived类,如何通过Derived类的对象调用基类的函数fn1。

#include<bits/stdc++.h>
using namespace std;
class Base {
public:
	int fn1() { return 0; }
	int fn2() { return 0; }
};
class Derived: private Base {
public:
	int fu1() {
		return Base::fn1();

	}
	int fu2() {
		return Base::fn2();

	}

};
int main()
{
	Derived d1;
	d1.fu1();
	d1.fu2();
}