If the title isn’t clear, the code should help clarify:
// .h file
template<class T> class DF_Vector3
{
public:
T x, y, z;
static const DF_Vector3 ZERO;
DF_Vector3() {}
DF_Vector3( T F );
DF_Vector3( T X, T Y, T Z );
};
typedef DF_Vector3<DF_FLOAT> DF_Vector3F;
// .cpp file
template<> const DF_Vector3F DF_Vector3F::ZERO( 0.0f, 0.0f, 0.0f ); // ERROR: Explicit specialization of 'ZERO' after instantiation
The compiler subsequently cites another location where DF_Vector3F::ZERO is referenced and states: “Implicit instantiation first required here.”
The Visual Studio 2010 compiler doesn’t seem to mind this. However, Apple’s CLANG (LLVM) compiler does not like it (it’s the one complaining).
Is there a way to fix this? Thanks.
You cannot use the
typedefin the definition of the static members, because by the time you have atypedef, the class template is already instantiated, after which you cannot explicity specialized its member(s).You should do this:
Demo : http://ideone.com/AMWMC