/*
*程序的版权和版本声明部分:
*Copyright(c)2013,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:尚振伟
*完成日期:2014年5月17日
*版本号:v0.1
*对任务及求解方法的描述部分:
*输入描述:无
*问题描述:
*程序输入:
*程序输出:
*问题分析:
*算法设计:
*我的程序:
*/
#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(); // 错误,保护继承下,派生类对象不可访问基类的私有成员
gir.take();
gir.StrechNeck();
return 0;
}
结果展示:
心得体会:。。。。。。。。。。。