Major Game trouble

I am making a major game and implied the help of a video tuorial but i can't get the code to work
here is Player.cpp

1
2
3
4
5
6
7
8
9
10
11
#include "Library.h"

void PLAYER::AddExperience(int amount)
{
	SetExperience(experience + amount);
}

void PLAYER::AddGold(int amount)
{
	SetGold(gold + amount);
}


here is player.h

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

class PLAYER 
{
private:
	char name[32];
	int strength;
	int intelligence;
	int gold;
	int experience;
	int health;
	int maxhealth;
	int mana;
	int maxmana;
	int level;
public:
	void SetName(char* newname);
	char* GetName();
	void SetStrength(int newstr);
	int GetStrength();
	void SetIntelligence(int newint);
	int GetIntelligence();
	void SetGold(int newgold);
	void AddGold(int amount);
	int GetGold();
	void SetExperience(int newexperience);
	void AddExperience(int amount);
	int GetExperience();
	void SetHealth(int newhealth);
	void AddHealth(int amount);
	void LoseHealth(int amount);
	int GetHealth();
	void SetMaxHealth(int newmaxhealth);
	int GetMaxHealth();
	void SetMana(int newmana);
	void AddMana(int amount);
	void LoseMana(int amount);
	int GetMana();
	void SetMaxMana(int newmaxmana);
	int GetMaxMana();
};


here are the errors:

1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\game\game\player.cpp(5) : error C2653: 'PLAYER' : is not a class or namespace name
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\game\game\player.cpp(7) : error C2065: 'experience' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\game\game\player.cpp(7) : error C3861: 'SetExperience': identifier not found
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\game\game\player.cpp(10) : error C2653: 'PLAYER' : is not a class or namespace name
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\game\game\player.cpp(12) : error C2065: 'gold' : undeclared identifier
1>c:\documents and settings\timbo\my documents\visual studio 2008\projects\game\game\player.cpp(12) : error C3861: 'SetGold': identifier not found
1>Town.cpp

somebody tell me what is wrong with the code!
player.cpp needs to include player.h
1>Player.obj : error LNK2019: unresolved external symbol "public: void __thiscall PLAYER::SetExperience(int)" (?SetExperience@PLAYER@@QAEXH@Z) referenced in function "public: void __thiscall PLAYER::AddExperience(int)" (?AddExperience@PLAYER@@QAEXH@Z)

1>Player.obj : error LNK2019: unresolved external symbol "public: void __thiscall PLAYER::SetGold(int)" (?SetGold@PLAYER@@QAEXH@Z) referenced in function "public: void __thiscall PLAYER::AddGold(int)" (?AddGold@PLAYER@@QAEXH@Z)

1>C:\Documents and Settings\Timbo\My Documents\Visual Studio 2008\Projects\Game\Debug\Wrath Lands.exe : fatal error LNK1120: 2 unresolved externals

Thats the errors I get.
Allow me to translate ( linker language in bold, with my translation underneath):

unresolved external symbol "public: void __thiscall PLAYER::SetExperience(int)" (?SetExperience@PLAYER@@QAEXH@Z)

Cannot find the function PLAYER::SetExperience(int) (the bit following in brackets is the C++ managled name.)

referenced in function "public: void __thiscall PLAYER::AddExperience(int)"
That was called from the function PLAYER::AddExperience


In other words the linker is saying it can't find the two functions
PLAYER::SetExperience and PLAYER::SetGold

If the code you have given us so far for player.cpp is what you compiled, then the reason is obvious - you haven't written these functions yet.

Last edited on
if you look in player.h then i have
This is a function prototype: void SetExperience(int newexperience); in player.h

Where is the function body? This is why the linker is complaining.
Last edited on
could you please type the code and show me
In player cpp - you add the function body for SetExperience:

1
2
3
4
void PLAYER::SetExperience(int newexperience)
{
	experience =  newexperience
}

(or you can do it as an in-line function in player.h as it is a small function)
The same for theSetGold function (and all the other remaining functions you have declared in the player class - they all need bodies before you can use them -or you will get the linker errors.)

Last edited on
You are probably not linking against both main.o(bj) and player.o(bj) since you were originally including player.cpp directly in main.cpp.
to jsmith
Was that in another post somewhere??
Last edited on
I inferred that was the problem in my first response. It was never confirmed by the original poster, but I assumed that was the problem since the poster never said otherwise.
Topic archived. No new replies allowed.