#include <iostream>
using namespace std;
class Animal
{
public:
Animal() {}
void eat()
{
cout << "eat\n";
}
protected:
void play()
{
cout << "play\n";
}
private:
void drink()
{
cout << "drink\n";
}
};
class Giraffe: private Animal
{
public:
Giraffe() {}
void StrechNeck()
{
cout << "Strech neck \n";
}
void take()
{
eat(); // _正确,公有继承,对派生类可见______________
drink(); // ____错误,基类为私有,对派生类不可见___________
play(); // _____正确,基类为保护类,对派生类可见__________
}
};
int main()
{
Giraffe gir;
gir.eat(); // __错误_私有继承不可调用____________
gir.play(); // ___同上____________
gir.drink(); // ____同上___________
return 0;
}
12.1.2
最新推荐文章于 2023-12-20 17:11:48 发布