Type duplicate symbol player::player()in

Hey everyone! This is my first post in these forums so hello to all of you! :).

I'm a newcomer to c++ and I've been having problems with seperating class declarations and implementations into seperate source files. I'm using the eclipse IDE. Every time I put a declaration of the class in a header file and the implementation in a .cpp file I always get this kind of error.

'duplicate symbol player::player()in ./src/player.o and ./src/Fight LOL.'

I think I'm doing something wrong. If so can any of you pinpoint what I'm doing wrong?

PLAYER.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef PLAYER_H_
#define PLAYER_H_

///////

class player
{
private:
	unsigned short int playerHP;
	unsigned short int playerAttack;
	unsigned short int playerDefense;

public:
	player(); //constructor for player class
	~player(); //destructor
};


///////

#endif /* PLAYER_H_ */ 


PLAYER.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include "player.h"

player::player() //constructor implementation
{
        //initialise
	playerHP = 10;
	playerAttack = 0;
	playerDefense = 0;

        //output information on player.
	std::cout << "playerHP = " << playerHP << end;
        std::cout << "playerAttack = " << playerAttack << endl;
        std::cout << "playerDefense = " << playerDefense << endl;
}

player::~player() //destructor implementation
{
	//free up memory. SAFEE.
}


MAIN.CPP
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include "player.cpp"
using namespace std;

int main()
{
	player Hero; //A hero appears out of thin air and whatever
	return 0;
}


Thankyou in advance. I would really appreciate the help. Making unnecessarily massive source files is really not fun. x
Last edited on
You shouldn't include source files. In main.cpp, replace #include "player.cpp" with #include "player.h" .
Last edited on
You only #include headers, not cpp files. Never include player.cpp. Only include player.h

EDIT: too slow
Last edited on
Ahh thanks guys. I can't believe it was such a simple mistake. I'll look into why it should be headers only and work out what was up. But cheers very much people :)!
Topic archived. No new replies allowed.