Hello,
I have two files, one is the main.cpp and one a Game.cpp that I want to include with a header in main.cpp. In need the Pokitto::Core game in both .cpp files.
In Game.cpp or Game.h, mark Pokitto::Core game as extern, i.e.
extern Pokitto::Core game;
(There’s a decent explanation of this use of externhere.)
Though truthfully you don’t need to make an instance/variable, you can just use Pokitto::Core on its own because all the functions are static.
(Like I did in Noughts And Crosses.)
By the way, using namespace std; is usually considered bad practice for two reasons.
When it’s used in a header file it leaks out and affects all the code that comes after it
If two different namespaces use the same name for something and they’re both included, it can cause ambiguity that the compiler can’t resolve (as explained here and here)
The second problem is probably slightly less likely to happen in the Pokitto’s environment,
but the first one is still an issue.
The first issue doesn’t affect .cpp files so it’s fine to put them there, but try to avoid doing it in .h files.
[quote=“Pharap, post:2, topic:1052”]Though truthfully you don’t need to make an instance/variable, you can just use Pokitto::Core on its own because all the functions are static.[/quote]And how do I need to include Pokitto::Core to access game?