PLAYER class problem

hey guys im working on a text based rpg
and im doing my player class

this is the code ill post the error at the bottom

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
// PLAYER CLASS

class PLAYER
{
private:

	//DATA MEMBERS FOR PLAYER CLASS
	char name[32];
	int strength;
	int intelligence;
	int gold;
	int experience;
	int health;
	int maxhealth;
	int Potion;
	int maxPotion;
	int level;

public:
	bool SetName(char *newName);
	char* GetName();
	void SetStrength(int newstr);
	int GetStrength();
	void SetIntel(int newint);
	int GetIntel();
	void SetGold(int newGold);
	void AddGold(int amount);
	int GetGold();
	void SetXp(int newXp);
	void AddXp(int amount);
	int GetXp();
	void SetHealth(int newHealth);
	void AddHealth(int value);
	void LoseHealth(int value);
	int GetHealth();
	void SetMaxHealth(int newMaxHealth);
	int GetMaxHealth();
	void SetPotion(int newPotion);
	void AddPotion(int amount);
	void LosePotion(int amount);
	int GetPotion();
	void SetMaxPotion(int newPotion);
	int GetMaxPotion();
};


here's the error im getting

Error 1 error C2011: 'PLAYER' : 'class' type redefinition c:\users\x d y n a s 7 y\desktop\afternoon\runesofsarnac\runesofsarnac\player.h 4


1) The console is a terrible medium for games. Save yourself a headache and get a graphical lib designed for making games (like SFML). You actually might be surpised how easy it is.

2) I was never a fan of private vars with dozens of get/set functions. I mean I understand you're trying to be OOP concious, but really this is a little ridiculous, don't you agree? I mean writing all those get/sets is really just a giant waste of time.

3) As for your actual question... read this: http://www.cplusplus.com/forum/articles/10627/#msg49679
thanks man, that worked i do agree a game lib would be better but its a strictly text based thing
im in school and working on a project and we have to learn the basic tedious stuff lol

and i did declare it twice...

thanks man i appreciate your help...
im in school


That explains it.

I bet they also told you "never make data members public" or some other BS to that effect.

*curses most C++ teachers*

Anyway, glad it's working! ^^
they said only use private data members for things that you do not want to change
anything changeable is to be in public
That doesn't make much sense, since a setter's only job is to change a variable's state (ideally, enforcing an invariant).
my getters and setters are public though only the declarations are in private
Getters and setters must be public, the whole point of having them is to keep the data members they refer to private. As far as I know, the only reason to have getters/setters (in other words, the only reason to keep data members private) would be to enforce an invariant, making sure the data always has reasonable state.

I think you're mixing things up a bit here:

only the declarations are in private

The getters and setters have to be declared too, and they're declared to be public.
Last edited on
you're right im still a noob at C++ im just going by what i've been learning so far...
Nothing wrong with that, just take what your teachers say with a big pinch of salt. If you're interested in doing some study on your own, I recommend Stroustrup's book Programming Principles and Practices Using C++.
thats the book we're using... lol
Bjarne Stroustrup lol
Topic archived. No new replies allowed.