c++ - undefined reference to static member variable in a static member function -
this question has answer here:
- undefined reference static class member 7 answers
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
Post a Comment