/
rgd045
/
cpp-oop-basics
Обзор
Документация
Войти
/
rgd045
/
cpp-oop-basics
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
projects/inheritance/main.cpp
41 строка
837 B
OMP Education
Add modules
28 июн 2024, 01:09
28 июн 2024, 01:09
0ef3df8
Код
Авторство
О чём код?
// SPDX-FileCopyrightText: 2023 Open Mobile Platform LLC <edu@omp.ru> // SPDX-License-Identifier: BSD-3-Clause #include <iostream> class Enemy { private: std::string m_name = {}; protected: int m_hp = 0; public: Enemy(){}; Enemy(std::string name, int hp): m_name {name}, m_hp {hp}{ } void display() { std::cout << "Enemy: " << m_name << " with hp = " << m_hp << std::endl; } void sleep() { std::cout << "Enemy: sleep" << std::endl; } }; class Mage: public Enemy { protected: int m_mp = 0; public: Mage(std::string name, int hp, int mp) : Enemy(name, hp), m_mp{mp} { } }; int main() { Mage mage {"Koschei the Deathless", 20, 50}; mage.display(); return 0; }