Is there a way to pass an object/pointer to object to a function outside of a loop?
eg.
Code:
int main()
{
cout << "Welcome. Please choose your class:\n\n";
cout << "K.\n\nKnight\nHP:100\nAttack:10\nDefence:10\n\n";
cout << "N.\n\nNormal Person\nHP:100\nAttack:8\nDefence:12\n\n";
while (true)
{
char selection = cin.get();
cin.ignore();
if ( selection == 'k' or selection == 'K')
{
cout << "Knight." << "\n";
auto_ptr<Character> Hero(new Character("Knight",100,10,10,0,1));// set the values for the character
battle(*Hero, *Enemy1); // Passes the Character Hero to the battle function
break;
}
if ( selection == 'n' or selection == 'N')
{
cout << "Normal Person." << "\n";
auto_ptr<Character> Hero(new Character("Normal Person",100,8,12,0,1));
battle(*Hero, *Enemy1);
break;
}
}
cout << "Exiting...";
return 0;
}
I'm doing that right now, but what I'd like to do is this:
Code:
int main()
{
cout << "Welcome. Please choose your class:\n\n";
cout << "K.\n\nKnight\nHP:100\nAttack:10\nDefence:10\n\n";
cout << "N.\n\nNormal Person\nHP:100\nAttack:8\nDefence:12\n\n";
while (true)
{
char selection = cin.get();
cin.ignore();
if ( selection == 'k' or selection == 'K')
{
cout << "Knight." << "\n";
auto_ptr<Character> Hero(new Character("Knight",100,10,10,0,1));// set the values for the character
}
if ( selection == 'n' or selection == 'N')
{
cout << "Normal Person." << "\n";
auto_ptr<Character> Hero(new Character("Normal Person",100,8,12,0,1));
}
battle(*Hero,*Enemy1);
break;
}
cout << "Exiting...";
return 0;
}
So that all I'd have to do is make the object, and call the battle function once total instead of once in every loop.
Help is appreciated.