Question on code
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.)
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;
Something like
Spell fireball("fireball");
then
std::cout << spell << std::endl;
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!";
}
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!";
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement