我有:
template<typename TypeA, typename TypeB>
class MyClass
{
public:
static TypeA StaticA;
static TypeB StaticB;
//...other stuff....
};
如何初始化“StaticA”(和 StaticB)?
如果我这样做:(在头文件中,在类的声明下但不在里面)
template<>
typename MyClass<TypeA, TypeB>::TypeA MyClass<TypeA, TypeB>::StaticA = TypeA();
给我:
'TypeA' was not declared in this scope.
'TypeB' was not declared in this scope.
template argument 1 is invalid
template argument 2 is invalid
和这个:
template<typename TypeA, typename TypeB>
typename MyClass<TypeA, TypeB>::TypeA MyClass<TypeA, TypeB>::StaticA = TypeA();
给我:
conflicting declaration 'typename MyClass<TypeA, TypeB>::TypeA MyClass<TypeA, TypeB>::StaticA'
'MyClass<TypeA, TypeB>::StaticA' has a previous declaration as 'TypeA MyClass<TypeA, TypeB>::StaticA'
declaration of 'TypeA MyClass<TypeA, TypeB>::StaticA' outside of class is not definition [-fpermissive]
初始化使用模板参数作为类型的模板化类的静态成员的正确方法是什么?