Hmm... I don't want to discourage you, but it's often best to learn to walk before you run, or you will definitely trip and fall flat on your face. I think it's awesome that you guys are working on a text based RPG, but if you're implementing classes without understanding more fundamental concepts like scope, you will quickly become frustrated.
Anyway... yes, you can have Eon available to other functions, but those functions have to refer to Eon as you declared it in your main .cpp file. You do that by using the extern keyword.
If this is your main .cpp file...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
. . .
#include "Globals.h"
#include "Player.h"
using namespace std;
Player Eon; // Eon is now globally available to other functions
int main()
{
string Name;
cout << "Welcome to the Epic World of Woot" << endl;
. . .
| |
then your other cpp files have to understand that Eon is a variable (or object) of type Player that was declared elsewhere, and to use that declaration as the current declaration.
1 2 3 4 5 6 7 8 9
|
// someother.cpp that uses Eon
#include "Player.h"
void eon_test(void);
void eon_test(void)
{
extern Player Eon;
cout << Eon.getName() << endl;
}
| |
Similarly, if you haven't declared these functions in an included header, you need to use the extern keyword to tell your main .cpp file that these functions exist.
While the above example will work, it is
very poor programming, and I do not recommend you pursue this model. More ideally, you should write your functions so that they accept a parameter of reference to Player or pointer to Player, and then pass Eon to those functions. Not only is this more efficient, it is significantly less prone to error due to scope conflicts.