⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animalclassmultipleconstructors.cpp

📁 C++ sample code, for the book: C++ black book, including templates, exceptional handling.
💻 CPP
字号:
#include <iostream>
#include <string>
using namespace std;

class animal 
{
    string name;
public:
    void eat() {cout << "Eating..." << endl;};
    void sleep() {cout << "Sleeping..." << endl;};
    void breathe() {cout << "Breathing..." << endl;};
    animal(string s) {name = s;}
};

class anaconda : public virtual animal
{
    int weight;
public:
    void walk() {cout << "Slithering..." << endl;}
    anaconda(int w, string s) : animal(s){weight = w;}
};

class zebra : public virtual animal
{
    int weight;
public:
    void walk() {cout << "Sauntering..." << endl;}
    zebra(int w, string s) : animal(s){weight = w;}
};

class zoo : public anaconda, public zebra
{
public:
    zoo(int weight, string name) : animal(name), anaconda(weight, name), zebra(weight,name){}
};

int main()
{
    zoo z(1000, "Cuddles");

    z.eat();
    z.breathe();
    z.sleep();

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -