there were no errors but the linker is shouting too much |
Unless I'm misunderstanding you, you mean that the linker is reporting errors, yes? Which makes your "no errors" comment somewhat baffling.
Also, if you have error messages,
tell us what they are, rather than just dropping hints that you have some.
The problem is with all the global variables you're defining in globals.h. That file is getting included in every source file, which means that those globals are being defined in every single translation unit. Hence, multiple definitions.
This doesn't apply to const globals; in C++, those have internal linkage only, so you can have those definitions in multiple units.
some of the ftns doesnt work withouth inlcudig the other file |
The first thing to say about using non-const global variables, is: as much as possible, DON'T. They're problematic in all sorts of ways (and I'm sure you can find explanations why in less time than it would take me to type them). If your functions need certain variables to work, then pass them as arguments. If your classes need certain variables to persist, then make them data members of that class.
If you really, really need a global variable (and you probably don't), and it's not const, then you need the definition in one place, and one place only - so not a header file - and then you need an
extern declaration of that global in the other places that need to use it.
So, in one source file, you want:
Character player1;
Then in a header file:
extern Character player1;