Template specialization with static data member
-
I get LNK2005 errors with the static CRuntimeClass datamember of the specialized template Why? I simplified the classes to highlight the problem. TXBase contains special algorithms and also the CRuntimeClass functions and static classTXBase to make RUNTIME_CLASS things work. //////////////////////////////////////////////////////////// // TXView template //////////////////////////////////////////////////////////// #undef CLASS_NAME #define CLASS_NAME classTXView_##BASE template < class BASE > class TXView : public TXBase < BASE > { public: TXView(UINT nIDTemplate = 0); virtual CRuntimeClass* GetRuntimeClass(); static const CRuntimeClass CLASS_NAME; }; template < class BASE > TXView< BASE >::TXView(UINT nIDTemplate /*= 0*/) : TXBase< BASE >::TXBase(nIDTemplate) { } template < class BASE > const CRuntimeClass TXView::CLASS_NAME = { "TXView", sizeof(class TXView), 0xFFFF, TXView::CreateObject, TXView::_GetBaseClass, 0 }; template < class BASE > CRuntimeClass* TXView::GetRuntimeClass() { return (CRuntimeClass*)&TXView::CLASS_NAME; } ///////////////////////////////////////////////////////////////// // Specialized template for FormView ///////////////////////////////////////////////////////////////// #undef CLASS_NAME #define CLASS_NAME classTXView_##CFormView template <> class TXView < CFormView > : public TXBase < CFormView > { public: inline TXView(UINT nIDTemplate = 0); inline virtual CRuntimeClass* GetRuntimeClass(); static const CRuntimeClass CLASS_NAME; }; template <> inline TXView< CFormView >::TXView(UINT nIDTemplate /*= 0*/) : TXBase< CFormView >(nIDTemplate) { } template <> const CRuntimeClass TXView::CLASS_NAME = { "TXView", sizeof(TXView), 0xFFFF, TXView::CreateObject, &TXView::_GetBaseClass, 0 }; template <> inline CRuntimeClass* TXView::GetRuntimeClass() { return (CRuntimeClass*)&TXView::CLASS_NAME; } Thanks if you can help!