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

📄 overriding_boss.cpp

📁 the source of dev_c++ most of them for game development
💻 CPP
字号:
//Overriding Boss
//Demonstrates calling and overriding base member functions

#include <iostream>

using namespace std;

class Enemy
{
public:
    Enemy(int damage = 10): m_Damage(damage)
    {}

    void Taunt() const
    { cout << "The enemy says he will fight you.\n"; }  

    void Attack() const
    { cout << "Attack! Inflicts " << m_Damage << " damage points."; }
 
private:
    int m_Damage;
};

class Boss : public Enemy
{
public:
    Boss(int damage = 30): Enemy(damage) //call base constructor with argument
    {}

    void Taunt() const
    { cout << "The boss says he will end your pitiful existence.\n"; }  

    void Attack() const 
    {
        Enemy::Attack();
        cout << " And laughs heartily at you.\n";
    }   
};

int main()
{
    cout << "Creating an enemy.\n";
    Enemy enemy1;
    enemy1.Taunt();
    enemy1.Attack();

    cout << "\n\nCreating a boss.\n";
    Boss boss1;
    boss1.Taunt();
    boss1.Attack();

    return 0;
}

⌨️ 快捷键说明

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