I have a problem initializing a static const member. In the template class, I define the const member and initialize it outside the class.
When I include the .h file, where this class is implemented in several .cpp files, I get the LNK2005 error message (I use VS2010), which says that the constant is already defined .
// List.hpp template <class T> class List { static const double TRIM_THRESHOLD; }; template <class T> const double List<T>::TRIM_THRESHOLD = 0.8;
I tried putting member initialization in a .cpp file, but then I get a linker error saying that the constant is not defined at all. If the list is not a template, and I put the initialization in the .cpp file, everything is fine.
Is there a solution for this situation? I already have # ifdef / define sentences around the file, and this is definitely not a solution.
c ++ static const visual-c ++ - 2010
Gratian lup
source share