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

📄 abstract_creature.cpp

📁 the source of dev_c++ most of them for game development
💻 CPP
字号:
//Abstract Creature
//Demonstrates abstract classes

#include <iostream>
using namespace std;

class Creature  //abstract class
{
public:
    Creature(int health = 100): m_Health(health)
    {}
    
    virtual void Greet() const = 0;   //a pure virtual member function

    virtual void DisplayHealth() const
    { cout << "Health: " << m_Health << endl; }

protected:
    int m_Health;
};

class Orc : public Creature
{
public:
    Orc(int health = 120): Creature(health)
    {}

    virtual void Greet() const
    { cout << "The orc grunts hello.\n"; }
};

int main()
{
    Creature* pCreature = new Orc();
    pCreature->Greet();
    pCreature->DisplayHealth();

    return 0;
}

⌨️ 快捷键说明

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