c++ - undefined reference to static member variable in a static member function -


this question has answer here:

here header file:

class mapobject: public screenobject {     static float xoffset, yoffset; public:     static float getxoffset() {         return xoffset;     }  };  #endif // mapobject_h 

however on line return xoffset; following error: undefined reference `mapobject::xoffset' why?

put in source file (by looks of mapobject.cpp)

#include "mapobject.h"  float mapobject::xoffset = 0; float mapobject::yoffset = 0;   //... rest of mapobject code here... 

in c++ non-const static members must both declared in class definition , defined global scope give linker reference.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -