Question on code

Started by
3 comments, last by Psych0 P3ngu1n 13 years, 11 months ago
int main() { Ogre bill; Ogre ted; Spell fireball; Spell thunderbolt; Spell freezeray; Spell spells[] = { fireball, thunderbolt, freezeray }; Spell &spell = spells[rand() % 3]; bill.SpellUse(spell); ted.SpellUse(spell); } here is code that Rip-Off gave me a few days ago to help with a lab for class, for my own knowledge however, i wanted to know if there was a way to show what spell was being used when the application was ran. If so, can you please show me the code for it. Thanks for taking time to read my thread. (and reply if you do.)
Advertisement
When you create the spells give them a string so that they know which spell they are. Then after you assign to spell print out the string you gave it previously.

Something like
Spell fireball("fireball");
then
std::cout << spell << std::endl;
alright thanks for help.
you could compare the memory addresses as this is really the only property in which those objects differ.

int main()
{
Ogre bill;
Ogre ted;
Spell fireball;
Spell thunderbolt;
Spell freezeray;

Spell spells[] = { fireball, thunderbolt, freezeray };
Spell &spell = spells[rand() % 3];

if (&spell == &fireball) {
cout << "Yay! Fireball!";
}
thank you stone, your way was a little bit easier to do. but both worked for me.

This topic is closed to new replies.

Advertisement