Hello everyone,
Today I started coding when suddenly these scums of C2146 and C4430 got me in troubles. I tried to avoid them using my powerful Google skills but unfortunately they did not get away, and that's why I'm relying to you now to find where the errors are:
Here's the .h:
Thanks for your reply. First the somewhere else is in global space : I declared the 'lol' namespace in a file called "Namespaces.h" and we usually declare namespaces in global space.
You're still not giving us the information that will help us. Please could you show us the complete error messages, including the line numbers.
And please show us the code that's generating these errors. If there's too much code to post, then try and create a minimal but complete set of code that still generates the error.
First off, declaring global variables is considered bad form, and in case of your project you're only going to get errors when you try to link your files. Why? Because you're declaring your global variables in a header file. #include is a glorified copy-paste, unlike Java's import. When your linker tries to link the two files, it'll find duplicate variables in your source files, act all confused about which matters, throw a hissy fit, and then go back to sleeping.
You can declare global variables in a header file, but to do so you'll need to use the extern keyword, and those variables will need to actually exist in exactly one source file in your project.
Second, I see something strangely circular here, even with your #pragma.
LoadingObject.h: #include "Namespaces.h"
Namespaces.h: #include "LoadingObject.h"
...why exactly does LoadingObject.h need Namespaces.h to be included if all that's in Namespaces.h are global variables?
As a starting fix for issue #2, just include Namespaces.h only in places where its globals are used. :D
As for issue #1... weeell, that's a bit more complicated. Ideally, you wouldn't use global variables and would have a class/struct designed primarily to store that data that you'd pass around references/pointers to when you need to access it.
You could also use a forward declaration1 to be a temporary fix. As Albatross mentioned you should look into a refractoring of your code because the design isn't really the best. Global variables aren't nessisarily bad but in this case they are unneeded and will cause you many headaches in the future.
Instead of having a global pointer to everything I would just pass a object that holds all that information in as a a parameter. I usually create a context object which holds all the information I might need and pass that into other classes (Usually other game states) through their constructors. For example.
This will hold most of the main information that I might need to pass between my different states. It includes the window, my texture manager, font manager and the player controller. You might want to include different things but that is up to you. The point it it makes a object that you can easily pass everything you might need to another class through the ctor.
Here is my constructor from my Main Menu state which shows how it can be used. Most of it you won't be able to understand completely without seeing the different classes but it will give you a general idea.
Wow thanks for this useful piece of advice, I'm new to game programming so any kind of help is really important for me. What i'm actually doing is a kind of test, so of course I do not do everything the right way, I am still lraning. What I just did is creating a method like loaduV(floats, bools and other things)
But yeah you are right I should have used a struct.
Anyway thanks for your help
No problem and don't worry about making some mistakes or bad designs when you are just starting. Game development can be a very challenging field of programming so everyone makes tons of mistakes when they are doing it (I know I have many many times).
What matters is that you are out there actually programming and trying new things. That is really the only way to learn in my opinion.
Anyways wish you the best of luck with your project and if you need anymore help feel free to ask.