2014-12周-项目一(3)

来源:互联网 发布:linux命令行登录mysql 编辑:程序博客网 时间:2024/06/13 09:07
/**程序的版权和版本声明部分:*Copyright(c)2014,烟台大学计算机学院学生*All rights reserved.*文件名称:*作者:刘晓晓*完成日期:2014年 05月13号*版本号:v1.0*对任务及求解方法的描述部分:*输入描述: 无*问题描述:*程序输出:无*问题分析:*算法设计:*/#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;}

0 0
原创粉丝点击