double definition help
hello, i am getting a compile error for my program, i have been getting this error fairly frequently.
Main.cpp||In function 'int main()':|
Main.cpp|5|warning: unused variable 'player' [-Wunused-variable]|
obj\Debug\Hero.o||In function `ZN4Hero9gethealthEv':|
Hero.cpp|4|multiple definition of `Hero::gethealth()'|
|4|first defined here|
||=== Build finished: 2 errors, 1 warnings ===|
main.cpp
1 2 3 4 5 6 7
|
#include "Main.h"
#include "Hero.cpp"
int main()
{
Hero player;
return 0;
}
|
main.h
#include <iostream>
Hero.cpp
1 2 3 4 5 6
|
#include "Hero.h"
int Hero::gethealth()
{
return health;
}
|
hero.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
class Hero
{
public:
int getexp();
int gethealth();
int sethealth();
int setexp();
private:
int health;
int maxhealth;
int exp;
};
|
Never include source modules (files with .cpp extensions), unless it contains template definitions.
Wazzak
thx
Topic archived. No new replies allowed.