+ 2

abstact class

#include <iostream> using namespace std; class Enemy { public: virtual void attack() = 0; }; class Ninja: public Enemy { public: void attack() { cout << "Ninja!"<<endl; } }; class Monster: public Enemy { public: void attack() { cout << "Monster!"<<endl; } }; int main() { Ninja n; Monster m; Enemy *e1 = &n; Enemy *e2 = &m; e1->attack(); e2->attack(); return 0; } where is abstraction please tell me friends.....please help me.

25th Oct 2017, 1:31 PM
Shivani Goyal
2 Respuestas
+ 2
class Enemy { public: virtual void attack() { cout << "Enemy attacks"; } }; class Ninja : public Enemy { public: void attack () { cout << "Ninja attacks"; } };
20th Nov 2020, 3:03 AM
Jason Chew
Jason Chew - avatar