+ 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.
1 Réponse
+ 2
class Enemy {
public:
virtual void attack() {
cout << "Enemy attacks"; }
};
class Ninja : public Enemy {
public:
void attack () {
cout << "Ninja attacks"; }
};