繁体   English   中英

模板类中的静态变量导致C2371'重新定义; 不同的基本类型

[英]Static variable in template class causing C2371 'redefinition; different basic types'

我有一个带有静态成员变量的模板类。 但是,在编译时,出现以下错误:

C2371: 'S_TYPES' : redefinition; different basic types

这是有问题的课程:

// This all is in Type.h

template<class T>
class Type
{
private:
    static std::map<unsigned int, Type<T>> S_TYPES;
};

template<class T>
std::map<unsigned int, Type<T>> Type<T>::S_TYPES;

如何在这里解决错误?

OP看到错误后立即编辑了问题:您正在定义与声明的类型不同的类型:

template<class T>
class Type
{
private:
    static std::map<unsigned int, Type<T>> S_TYPES;
};

template<class T>
std::map<unsigned int, Type<T>, TypeInfoComparator> Type<T>::S_TYPES; // different

您应该确保它们匹配:

template<class T>
class Type
{
private:
    static std::map<unsigned int, Type<T>> S_TYPES;
};

template<class T>
std::map<unsigned int, Type<T>> Type<T>::S_TYPES;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM