0

If i declare datatype of pure virtual function and used that pure function by assigning different values to it .i get con

The code is given below: #include <iostream> using namespace std; class Enemy { private : int a; public: virtual void attack(int a) = 0; }; class Ninja: public Enemy { public: void attack(int a) { cout << "Ninja!"<<endl; return attack(a); } }; class Monster: public Enemy { public: void attack(int a) { cout << "Monster!"<<endl; return attack(a); } }; int main() { Ninja n; Monster m; Enemy *e1 = &n; Enemy *e2 = &m; e1->attack(5); e2->attack(6); return 0; }

18th Dec 2017, 3:55 PM
Rao Kamran
Rao Kamran - avatar
1 Odpowiedź