"file.h"
template <class ClassType>
class NewClass
{
protected:
public:
NewClass() {}
~NewClass() {}
static long INITIAL_SIZE;
};
"file.cpp"
template<class ClassType>
long NewClass<ClassType>::INITIAL_SIZE{ 50 };
"usage file"
in the main function
std::cout << NewClass<char>::INITIAL_SIZE << std::endl;
Can someone please tell me why this gives me a "lnk2001 unresolved external symbol" error?
So whenever I moved:
template<class ClassType>
long NewClass<ClassType>::INITIAL_SIZE{ 50 };
to the header file it would throw different error... but once I changed {50} to = 50:
template<class ClassType>
long NewClass<ClassType>::INITIAL_SIZE = 50;
it worked. I don't understand why, but the problem was the way I was setting the variable.