[SOLVED] creating a subclass from an abstract class EDITED : NEW PROBLEM

I am trying to use a keyListener class from OIS (Object Oriented Input system) that looks as follows :

1
2
3
4
5
6
7
8
9
//from OIS.h

class _OISExport KeyListener
	{
	public:
		virtual ~KeyListener() {}
		virtual bool keyPressed( const KeyEvent &arg ) = 0;
		virtual bool keyReleased( const KeyEvent &arg ) = 0;		
	};


I want to write a subclass (GH_KeyMaps) that is just a "copy" of this KeyListenerm but with a member added, namely a pointer to a class of mine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//file : GH_KeyMap.h

#ifndef GH_KEYMAP_H
#define GH_KEYMAP_H
#include "OIS.h"
#include "BaseApp.h"
class BaseApp; //forward declaration
class GH_KeyMap : public OIS::KeyListener
{
public :
	GH_KeyMap(BaseApp *mBA);
	~GH_KeyMap();
private:
	BaseApp *BA;
};
#endif //GH_KEYMAP_H 


The definition of the constructor/deconstructor is in the GH_KeyMap.cpp file
Initialising the BaseApp pointer to the one given when creating an GH_KeyMap Object.
1
2
3
4
//file : GH_KeyMap.cpp
#include "GH_KeyMap.h"
GH_KeyMap::GH_KeyMap(BaseApp *mBA):BA(mBA){}
GH_KeyMap::~GH_KeyMap(){}


From this point, I should be able to create subclasses from GH_KeyMap, that will contain a pointer to my baseApp.

Finally an example of a 'concrete' class that will be used :
1
2
3
4
5
6
7
8
9
10
11
12
//file : GH_Home_KM.h

#ifndef GH_HOME_KM_H
#define GH_HOME_KM_H
#include "GH_KeyMap.h"

class GH_Home_KM : public GH_KeyMap
{
	bool keyPressed(const OIS::KeyEvent &e);
	bool keyReleased(const OIS::KeyEvent &e);
};
#endif //GH_HOME_KM_H 


Those are finally defined in the cpp file :
1
2
3
4
5
6
7
8
9
10
11
12
//file : GH_Home_KM.cpp

#include "GH_Home_KM.h"

bool GH_Home_KM::keyReleased(const OIS::KeyEvent &e)
{
	std::cout<<"keyReleased"<<std::endl;
}
bool GH_Home_KM::keyPressed(const OIS::KeyEvent &e)
{
	std::cout<<"keyPressed"<<std::endl;
}


Untill here everything is fine...

When i include the GH_Home_KM.h file in my BaseApp.h file,
I get an error :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//file : BaseApp.h

#ifndef BASEAPP_H
#define BASEAPP_H

#include "OgreRoot.h"
#include "OgreRenderWindow.h"
#include "OgreOverlayManager.h"
#include "OIS.h"
#include "GH_KeyMap.h" //included

#include "GH_Home_KM.h"//HERE IT GOES WRONG
//GH_Home_KM.h doesn't know what a GH_KeyMap is ??

#include "utilities.h"
#include "Calibrator.h"

class GH_KeyMap; //forward declaration.
class BaseApp
{
public:
	BaseApp();
	~BaseApp();
	void startApp(void);
	bool setup(void);
	void loadRenderSystem(void);
	void chooseSceneManager(void);
	void createRenderWindow(void);
	void createInputSystem(void);
	void setResources(void);
	void setOverlayManager(void);
	void createCamera(void);
	void setupCalibration(void);

	void render(void);


protected:
	Ogre::Root *mRoot;
	Ogre::SceneManager *mSceneMgr;
	Ogre::RenderWindow *mRenderWindow;
	Ogre::OverlayManager *mOverlManager;
	Ogre::Camera *mCamera;
	Ogre::SceneNode *mCamNode;

	OIS::JoyStick *mJoystick;
	OIS::Keyboard *mKeyboard;
	OIS::Mouse *mMouse;
	
	std::map<std::string,GH_KeyMap *> keyMaps;
	Calibrator mCalibrator;
};

#endif 


//ERROR :
1
2
3
4
5
6
7
8
9
10
1
1>Compiling...
1>GH_Home_KM.cpp
1>GH_KeyMap.cpp
1>c:\documents and settings\purkinjer\my documents\visual studio 2008\projects\cleancalibrator\cleancalibrator\GH_Home_KM.h(7) : error C2504: 'GH_KeyMap' : base class undefined
1>driver.cpp
1>BaseApp.cpp
1>Build log was saved at "file://c:\Documents and Settings\PurkinjeR\My Documents\Visual Studio 2008\Projects\CleanCalibrator\CleanCalibrator\Release\BuildLog.htm"
1>CleanCalibrator - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


//Some extra information about where i am going to :
The point is to create a keymap for each different stage of the program.
Eg, in the startup screen keys have a different meaning than in the e.g. "calibration-stage".

So the plan was to create a class that is derived from the OIS keylistener class, that holds a pointer to the base application containing the keyboard itself, OIS setup stuff etc.
There I can then switch keymaps, by registering another keylistener subclass into OIS.
Keymaps would be stored in a std::map and so that map can be used to search & set a keymap through the pointer to the baseApp.

In other words, the baseApp would have a memberfunction : setKeyMap(std::string) that searches the right subclass and sets the keyboard listener to this.

for example I could have :
Home_KeyMap -> with definitions of what to do when pressed keys.
Calibration_KeyMap -> with other definitions for the keys.

then I could call my function setActiveKeyMap through the pointer to the baseApp contained in KeyMap, to switch between both keymaps.

thats about it, hope this is clear.

thanks in advance !
Geoffrey.

Last edited on
I think you have a circular header dependency problem here.
It starts in GH_KeyMap.cpp.

but my eyes have gone all funny now. I'll check again in a minute.

For now try commenting out line 6 - #include "BaseApp.h" in GH_KeyMap.h and see what happens.
Last edited on
solved thank you !
Topic archived. No new replies allowed.