< Previous | Contents | Next >

Using Inherited Members

Next, I call an inherited member function of the Boss object, which displays the exact same message as enemy1.Attack().

boss1.Attack();

That makes perfect sense because the same code is being executed and both objects have an m_Damage data member equal to 10. Notice that the function call looks the same as it did for enemy1. The fact that Boss inherited the member function from Enemy makes no difference in how the function is called.

Next, I get Boss to pull out its special attack, which displays the message Special Attack inflicts 30 damage points!

boss1.SpecialAttack();

The thing to notice about this is that SpecialAttack(), declared as a part of Boss, uses the data member m_Damage, declared in Enemy. Thats perfectly fine. Boss inherits m_Damage from Enemy and, in this example, the data member works like any other data member in the Boss class.