It seems like this should be basic but I am not seeing where I need to communicate the data here. This function gets called on by creature objects from two different classes. The "demonic attack" should be true for both class objects but for only one of the creature objects (balrog) should this block of code execute. My if condition is always true so this block of code is executing when both classes call it. How do I get the communication right so it only executes when the balrog class calls it?
Sorry, to be more clear, the function is my code but the client program is provided by my instructor and I have to get the data to communicate accordingly.
If you're meant to be using inheritance, I'd expect the code to look something like this:
1 2 3 4 5 6 7 8
int Balrog::getDamage() const
{
// Is this really meant to call the base class getDamage()?
int baseDamage = creature::getDamage(); // base damage value for all creatures?
// HERE, add damage for balrog
return damage;
}
You don't have a Balrog object call getDamage on a Demon object. The Balrog class has its own Damage function
I talked to my instructor and it turns out that I was misinterpreting the instructions and the statements for the different objects need to go in their respective classes.
You guys are right about the polymorphism and inheritance, and reading what you guys have to say is still helpful so I appreciate it!