01./*
02.* 程序的版权和版本声明部分:
03.* Copyright (c) 2011, 烟台大学计算机学院
04.* All rights reserved.
05.* 文件名称:test.cpp
06.* 作 者:刘芳
07.* 完成日期:2014 年05 月 17 日
08.* 版 本 号:v1.0
09.* 对任务及求解方法的描述部分:
10.* 输入描述:无
11.* 问题描述:
12.* 程序输出:
13.* 问题分析:略
14.* 算法设计:略
15.*/
#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;
}