OK so I have a Game class which contains an array of pointers to a Player class which is declared within the Game class like so: Players **gamblers
Now, the size of this array is based on the constructor argument. However, the user is the one who inputs the argument like so:
1 2 3 4 5 6 7 8
int main()
{
int number;
cout << "Input a number: ";
cin >> number;
(Class Name) name(number);
}
This means that the Game object has to by dynamically declared and cannot be initialized outside of the main function. This can be a problem. Whenever I want to access that particular object and it's member variables in other functions, I cannot because I can never know the arguments of the constructor. How would I be able to access the object and it's member variables and member functions within other functions? The only way I can think of doing this is by passing a reference or pointer to the object in the parameters of the function but that would tend to get tedious. Is there any other way of accomplishing this?
Alright so I've figured something out. I declared a global Game pointer and once the object is created, I pointed the global pointer to the object. (I know this is usually a problem but the object is created in main so I won't have to worry about it being accidentally deleted.) Then whenever I want to access that object inside another function, I simply use the pointer. Now I have one last question. Is this a bad thing? I've heard somewhere that global pointers are no good. Is this true? If so, why not and what would be my alternative?