Problem with enum in class

Hello everyone :) . I am doing a class, which will let me to draw signs to my game screen, to help testing. The main thing is, that I am doing first time it with enumeration, and I get a bunch of not understandable errors. So I hope, that there is anyone, who knows, what I am doing wrong, and could help me :)

Code:
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
#ifndef TEST_SIGNS
#define TEST_SIGNS

#include "objektas.h"
#include "vector2.h"


class Test_sign
{
public:

	enum _Color
	{
		green,
		yellow,
		red
	};

	object sign;

	Test_sign();
	void set_color(_Color color);
	void draw(vector2 pos);

protected:

	Texture green_sign, red_sign, yellow_sign;
};

Test_sign::Test_sign()
{
	green_sign.loadFromFile("gdata/graphics/signGreen.png");
	yellow_sign.loadFromFile("gdata/graphics/signGreen.png");
	red_sign.loadFromFile("gdata/graphics/signGreen.png");
}

void Test_sign::set_color(Test_sign::_Color color)
{
	if(color == green) sign.set_texture(&green_sign);
	else if (color == yellow) sign.set_texture(&yellow_sign);
	else sign.set_texture(&red_sign);
}

void Test_sign::draw(vector2 pos)
{
	sign.set_position(pos);
	sign.draw();
}

#endif 


Errors:
1
2
3
4
5
6
7
8
9
10
error LNK2005: "public: void __thiscall Test_sign::draw(class vector2)" (?draw@Test_sign@@QAEXVvector2@@@Z) already defined in main.obj
error LNK2005: "public: void __thiscall Test_sign::set_color(enum Test_sign::_Color)" (?set_color@Test_sign@@QAEXW4_Color@1@@Z) already defined in main.obj
error LNK2005: "public: __thiscall Test_sign::Test_sign(void)" (??0Test_sign@@QAE@XZ) already defined in main.obj
error LNK2005: "public: void __thiscall Test_sign::draw(class vector2)" (?draw@Test_sign@@QAEXVvector2@@@Z) already defined in main.obj
error LNK2005: "public: void __thiscall Test_sign::set_color(enum Test_sign::_Color)" (?set_color@Test_sign@@QAEXW4_Color@1@@Z) already defined in main.obj
error LNK2005: "public: __thiscall Test_sign::Test_sign(void)" (??0Test_sign@@QAE@XZ) already defined in main.obj
error LNK2005: "public: void __thiscall Test_sign::draw(class vector2)" (?draw@Test_sign@@QAEXVvector2@@@Z) already defined in main.obj
error LNK2005: "public: void __thiscall Test_sign::set_color(enum Test_sign::_Color)" (?set_color@Test_sign@@QAEXW4_Color@1@@Z) already defined in main.obj
error LNK2005: "public: __thiscall Test_sign::Test_sign(void)" (??0Test_sign@@QAE@XZ) already defined in main.obj
fatal error LNK1169: one or more multiply defined symbols found


Thanks :)
can you post your main too?
The problem is you're including implementations in your header file. This causes problems when you include your header file in more than one module.

The linker is trying to tell you that
1
2
3
Test_sign::Test_sign()
void Test_sign::set_color(Test_sign::_Color color) 
void Test_sign::draw(vector2 pos) 

are defined multiple times. This is because they are included multiple times. Move Test_sign::Test_sign(), void Test_sign::set_color(Test_sign::_Color color) and
void Test_sign::draw(vector2 pos) to a .cpp file. They do not belong in a .h file.




Thank you AbstractionAnon, it worked :)
You can keep the definitions inside the header but outside the class if you add the inline keyword to the definitions. Otherwise you violate the One Definition Rule and the linker complains about multiple redefinition.
Topic archived. No new replies allowed.