C++ static member of class template — linker warning “multiple definition” [duplicate]
问题 This question already has answers here : Why can templates only be implemented in the header file? (16 answers) Static member initialization in a class template (3 answers) Closed 2 years ago . Let's say for some reason, I want to have a class template MyTemp with some static data member smDummyVar : Mytemp.h #ifndef MY_TEMP_H #define MY_TEMP_H template<class T> class MyTemp{ ... private: static int smDummyVar; ... }; #include "MyTemp.cpp" #endif //MY_TEMP_H Mytemp.cpp ... template<class T>