I posted a question similar to this one before, but it seemed to die out.
Here is my problem: I have two classes using a singleton design pattern, and everything works fine. For our purposes one of the classes is called GameManager. The problem comes when I try to get the static instance of the GameManager from another class, let's say, Camera. I get a lot of parse errors before "*" from g++. Here are the parts of Camera and GameManager that i believe are causing problems:
GameManager.h
And the instance function for the GameManager:Code:#ifndef AC_GAMEMANAGER_H_ #define AC_GAMEMANAGER_H_ #ifdef _WINDOWS #include <windows.h> #endif #include <GL/gl.h> #include <GL/glu.h> #include <math.h> #include "SDL.h" #include "types.h" #include "UIManager.h" #include "Error.h" #include "Scene.h" #include "Keys.h" class GameManager { static GameManager *_instance; UIManager *uimanager; Scene scene; Keys keys; ac_int init(ac_void); ac_void loopGame(ac_void); ac_void renderScene(ac_void); GameManager() {} public: static GameManager *instance(ac_void); ac_void beginGameLoop(ac_void); /* Get and Set */ /** * @return the <code>Scene</code> object */ Scene getScene(ac_void) const { return scene; } /** * @return the <code>Keys</code> object */ Keys getKeys(ac_void) { return keys; } }; #endif /* AC_GAMEMANAGER_H_ */
Here are the problem parts in Camera:Code:GameManager *GameManager::_instance = 0; GameManager *GameManager::instance() { if (!_instance) { _instance = new GameManager(); _instance->init(); } return _instance; }
Camera.h
And the places I use the gameManager in the Camera.cpp file:Code:#ifndef AC_CAMERA_H_ #define AC_CAMERA_H_ #include <GL/gl.h> #include <GL/glu.h> #include <stdio.h> #include "SDL.h" #include <math.h> #include "UIManager.h" #include "GameManager.h" #include "MainFrame.h" #include "Keys.h" #include "Error.h" #include "version.h" class Camera { /* ... */ GameManager *gameManager; public: /* ... */ }; #endif
Here is the compiler output:Code:Camera::Camera() { /* ... */ gameManager = GameManager::instance(); } /** And inside a movement function: */ if(gameManager->getKeys().isActionDown("+forward")) { MoveCamera(speed); }
Note: The problem goes away when I don't use GameManager in Camera.Code:cd '/home/max/programming/c++/gl/angelchronicles/angelchronicles/debug' && WANT_AUTOCONF_2_5="1" WANT_AUTOMAKE_1_6="1" gmake -k -j1 compiling angelchronicles.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/Camera.h:104: error: syntax error before `*' token compiling LoadManager.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/Camera.h:104: error: syntax error before `*' token compiling Game.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/Camera.h:104: error: syntax error before `*' token compiling GameManager.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/Camera.h:104: error: syntax error before `*' token compiling Camera.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/GameSceneRender.h:29: error: ' Camera' is used as a type, but is not defined as a type. compiling Scene.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/GameManager.h:43: error: ' Scene' is used as a type, but is not defined as a type. /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/GameManager.h:63: error: parse error before `)' token /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/GameManager.h:68: error: ISO C++ forbids defining types within return type /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/GameManager.h:68: error: syntax error before `(' token compiling GameSceneRender.cpp (g++) /home/max/programming/c++/gl/angelchronicles/angelchronicles/src/Scene.h:51: error: syntax error before `*' token *** Exited with status: 2 ***
Thanks alot, and if you need more code just ask. Any suggestions? Thanks!



LinkBack URL
About LinkBacks



not sure what the problem is...