Hi,
I''m a beginner C++ programmer, and I''m having this problem, I hope someone can help
I have 2 classes, Warrior, and Rogue.
Here''s some code to help describe my problem:
void createCharacter()
{
cout << "Choose a character class: \n";
cout << "1) Warrior \n";
cout << "2) Rogue\n";
int input;
if(input == 1) {
createWarrior();
}
else if(input == 2) {
createRogue();
}
else {
cout << "Enter 1 or 2.\n";
system("cls");
createCharacter();
}
}
// I''ll skip createRogue for space-saving.
void createWarrior()
{
Warrior *Khan = new Warrior;
cout << "Khan''s strength is: " << Khan->getStr() << endl;
// etc.
}
Anyway.
If I have another function, say:
beginFirstScene()
{
int health_remaining = Khan->getHealth();
if(health_remaining == 0)
{
Khan->Die();
// This function plays a cool sound using FMOD
}
}
But the compiler (Dev-C++), says things like
Khan: undefined, first use in this function. etc etc.
I need a way to, when the user selects the ''class'', a way of setting their class as a global variable, so all functions can call, say
Khan->Die();
etc.
I''ve tried things like:
#define KHAN Warrior *Khan = new Warrior;
void some_function()
{
KHAN->Die();
}
But that doesn''t work.
=/
/me is very stuck.
Help is much appreciated.
Thanks,
renegade