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:
Here are code segments pertaining to the error: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
player.h
player.cppCode:#ifndef player_h #define player_h class player{ private: float posX; public: player(); float get_posX() {return posX;} }; #endif
box.hCode:#include "player.h" float posX = 100.0f; player::player(){ // code removed }
box.cppCode:#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
Thanks!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 }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.