Using an enum defined in class

Hello everyone.

I am trying to write a game in C++ with SDL, and I have a class that allows me to handle events.
The class is actually really simple: It takes the SDL_Event, then 2 variables from 2 different enum to determine for which Event and which Key should be checked, and then a variable that will be modified if the event happens.
Here is the class

EventParser.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "SDL.h"
#include "SDL_opengl.h"

template<class T>
class EventParser
{
public:
	enum EventType{
		KeyUp, KeyDown
	};
	enum KbdKey{
		LEFT, RIGHT, UP, DOWN
	};
	void parseEvent(SDL_Event e, EventType t, KbdKey k, T* var);
};


EventParser.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "EventParser.h"


template<class T>
void EventParser<T>::parseEvent(SDL_Event e, EventType t, KbdKey k, T* var)
{
	switch (t)
	{
	case t.KeyUp:
		switch (k)
		{
		case: k.LEFT:
			&var -= 1.0;
		default:
			break;
		}
	default:
		break;
	}
}


As of yet the variable only changes if the Left key has been released, it will be extended if the error has been solved.

Then, in my main.cpp file I define the Event and the EventParser as
1
2
SDL_Event event;
EventParser<float> ep;


And in a loop, the parseEvent function is called like this:
ep.parseEvent(event, ep.KeyUp, ep.LEFT, &xVariable);

However I get a linker error (not the first one I got when programming this game)
error LNK2019: unresolved external symbol "public: void __thiscall EventParser<float>::parseEvent(union SDL_Event,enum EventParser<float>::EventType,enum EventParser<float>::KbdKey,float *)" (?parseEvent@?$EventParser@M@@QAEXTSDL_Event@@W4EventType@1@W4KbdKey@1@PAM@Z) referenced in function _SDL_main C:\Users\PrideRage\Documents\Visual Studio 2012\Projects\SDL_Test\SDL_Test\main.obj SDL_Template

I have tried searching but I haven't found any solution that helped me here.

Thanks in advance for helping me.
move the definition of parseEvent to the header
Combine the header file and the cpp module in one header file.
Last edited on
Thanks for the answers, but why do I have to do it in one file?
I'm used to having a .h and a seperate .cpp file for a class.
Probably because of the template.
Thanks it works now. I can now continue working on this. Thanks alot :)
Thanks for the answers, but why do I have to do it in one file?
I'm used to having a .h and a seperate .cpp file for a class.


See this tutorial. Read the last section.

http://cplusplus.com/doc/tutorial/templates/

I also like separating the .h from the .cpp-ish stuff. So what I do is write my implementation file, but name it .tcpp ("t" stands for template), and then include the .tcpp file at the bottom of the .h file. The compiler doesn't know what to do with a .tcpp file, so it doesn't try to compile it. The template code is included through the header file, so the template users are happy, and the separation between header and implementation remains, so my sensibilities are happy. The header has one extra line in it, but I can live with that.
Topic archived. No new replies allowed.