Why use virtual member function | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 6

Why use virtual member function

9th Mar 2017, 9:21 AM
Amar Dahake
2 Réponses
+ 1
Supose I have a class called Hero with an attack function and i want that all my derived classes from hero implement this function different for example the attack of a ranged hero must be different from the attack of a melee hero , thats why we use the keyword "virtual" couse it allow subclasses to make different implementation of the same function (function attack on the example) deppending on what we need.
9th Mar 2017, 9:55 AM
Hector Sulbaran
Hector Sulbaran - avatar
+ 5
thanks
12th Mar 2017, 7:29 AM
Amar Dahake