Original Post
I''m writing a program that uses a class "player" to hold information about the current player. Here''s a little snippet of my code:
class player
{
public:
player(string, int, int, int, int, int);
~player(void);
void show_player_stats(void);
private:
string player_name;
int weapon_status;
int health;
int armor;
int money;
int experience;
};
void main(void)
{
create_new_player();
}
void create_new_player(void)
{
string name;
cout << "What is the name of your new player?";
cin >> name;
player p1(name,0,100,0,500,0);
p1.show_player_stats();
}
Ok, it works fine when I use p1.show_player_stats() in the create_new_player() function, because that''s where I created p1. But, other functions need to use p1 also. For example, on the main menu screen for the program, the user should be able to press "S" for the player stats - which would mean calling p1.show_player_stats(). But because p1 is private to create_new_player(), this doesn''t work and therefore I can''t call p1.show_player_stats() from my main_menu() function. Now that I''ve told you what I CAN''T do, can anyone tell me how it CAN work? Is this where I''d have to make p1 global? How would I do that? If making it global isn''t the solution, what is?