Reputation: 739
I have a big game engine to compile and it worked fine until I did some crazy adjustments. The compiler somehow cannot reconize my mean Game object and produce error C2061: syntax error : identifier 'Game'
, and it seems no matter what file I compile the error always points to a file called GameDataLoader.h
even there is absolutely no connection with this two files. Usually I think it is an inclusion problem but the fact is I have Game.h
included in every .h file necessary, right after the inclusion of stdafx.h and I have #pragama once
on top of it. I thought about circular inclusion problem but the #pragma once
should take care of that. Plus this inclusion directives works fine until I changed some file name and other messy stuff. I cleaned the entire solution and tried to rebuild it but still no luck (using VS2012).
I don't know if showing the code will help, but here is the code for gameDataLoader.h
. This isn't a file I wrote but it should work properly.
#pragma once
#include "stdafx.h"
#include "Game\Game.h" // Game.h included
class GameDataLoader
{
public:
GameDataLoader(){}
~GameDataLoader(){}
void GameDataLoader::loadGameProperties( Game *game, map<wstring, wstring> *properties, wstring gameInitFile);
virtual void loadGame(Game *game, wstring gameInitFile) = 0;
virtual void loadGUI(Game *game, wstring guiInitFile) = 0;
virtual void loadWorld(Game *game, wstring levelInitFile) = 0;
};
And I had errors exactly on those 4 lines with Game object. What could possibly be the problem? Double inclusion? Circular inclusion? Or did not include something and somewhere else?
Upvotes: 1
Views: 33085
Reputation: 254431
Most likely, Game.h
is including GameDataLoader.h
, either directly or indirectly, creating a circular dependency; but you forgot to show us Game.h
, so I can't be sure of that.
If that is the case, then #pragma once
(or the equivalent include guard) will mean that one of the headers will be included before the other, and declarations from the second won't be available to the first. It won't magically include both of them before each other, since that is impossible.
Luckily, GameDataLoader.h
doesn't need the full definition of Game
, since it only deals with pointers to it. So you can remove the inclusion of Game.h
and just declare class Game;
instead.
Upvotes: 12