I'm getting errors while trying to compile code using 2 classes, box and player. While looking for help online, I got the feeling that this is a fairly common problem, or the solution is at least obvious to the experienced programmer. Any help?
I'm getting the following errors:
Code:
player.obj : error LNK2005: "float posX" (?posX@@3MA) already defined in box.obj
Debug/Text1.exe : fatal error LNK1169: one or more multiply defined symbols found
Here are code segments pertaining to the error:
player.h
Code:
#ifndef player_h
#define player_h
class player{
private:
float posX;
public:
player();
float get_posX() {return posX;}
};
#endif
player.cpp
Code:
#include "player.h"
float posX = 100.0f;
player::player(){
// code removed
}
box.h
Code:
#ifndef box_h
#define box_h
class box{
private:
float posX;
public:
box();
box(float x,float y,float z,float w,float h,float l);
float get_posX() {return posX;}
};
#endif
box.cpp
Code:
#include "box.h"
float posX = 0.0f;
box::box(float x,float y,float z,float w,float h,float l){
// code removed
}
box::box(){
// code removed
}
Thanks!