How to solve an variable storage problem?

i did this to my global variables to try and get rid of them, but now there undefined to my entire program, even though they are public, did i do this right, and how do i solve this problem?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class VariableStorage
{
     public:
VariableStorage()
{
string SetType;       
string PlayerAge;
string PlayerName;
string PlayerGender;
string CharacterDetails;
string OpponentCharacterDetails;
string Continue;
string PlayAgain;
string Type;
int Attack;
int Defense;
int Health;
string Advantage;
string Disadvantage;
string MonsterName;
int Damage;
string OType;
int OAttack;
int ODefense;
int OHealth;
string OAdvantage;
string ODisadvantage;
string OMonsterName;
int ODamage;
long Earnings = 10;
long Money = 0;
long AmountExp = 10;
long TotalExp = 0;
long NewLevel = 0;
long LevelUp = 10;
long SkillPoints = 3;
long TotalSkillPoints = 0;
int TypeOfCharacter;
}
~VariableStorage(){}
private:
};
Last edited on
While it is true that they are public, now they only belong to objects of the VariableStorage class. Is there a specific reason that you want to get rid of your global variables, or is it just a matter of preference?
You are declaring all those variables inside the constructor instead of inside the class.

Declare them outside the constructor and initialize them inside it. Also if, you are not going to have public getter methods to return the private data just use a struct instead of a class because it defaults to public.


Looking at all those variables makes me wonder if you should just organize them into several separate classes. It would make things much more intuitive and manageable.
Last edited on
See my response in your other thread.
ok, if you would gladly reply to my next reply and try to fix or at least start me off that would be nice, thanks.

link to thread
http://www.cplusplus.com/forum/beginner/81836/
Topic archived. No new replies allowed.