Sign in to follow this  
Psych0 P3ngu1n

Question on code

Recommended Posts

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.)

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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!";
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this