#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;
}
第二学期第十二周项目1--长颈鹿类对动物类的继承
最新推荐文章于 2014-05-25 21:46:45 发布