#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: protected 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.3
最新推荐文章于 2019-08-13 09:31:02 发布