The sample code compiles without warning or error on Windows and Linux. It starts to get the -Wundefined-var-template
warning in XCode 9.
foo.h:
template <typename T>
struct myClass
{
static const char* name;
};
foo.cpp:
#include "foo.h"
template<>
const char *myClass<int>::name = "int";
warning: instantiation of variable 'myClass<int>::name' required here, but no definition is available [-Wundefined-var-template]
note: forward declaration of template entity is here
static const char *name;
^
note: add an explicit instantiation declaration to suppress this warning if 'myClass<int>::name' is explicitly instantiated in another translation unit