模板类中的静态变量导致 C2371 'redefinition; different basic types'
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;
相关文章:
- 我收到类中每个方法的"redefinition of"错误
- 头文件出现问题; "redefinition of class"
- DI 加速 C++14 和动态容器
- 尝试实施 PIMPL idom 时如何避免"redefinition; different basic types"
- 将 boost-di 与配置文件和共享库一起使用
- [BOOST] .DI装饰器图案
- G++ 编译器"redefinition…previously defined"
- Typedef redefinition with different types (Emscripten SDL2+O
- 在FTDI 2232H迷你模块上使用GPIO输入而不是TDO/DI
- C++错误"redefinition of 'string' as different kind of symbol"
- 在一个DFS中查找Di-Graph中的强烈连接组件
- "Typedef redefinition with different types" Clang中关于工作MSVC代码的错误
- C++ "'DOMDocument' : redefinition" Xercesc错误
- C++简单的类程序无法编译。我搞砸了包含标题吗? 'Error redefinition of a class'
- 将 Qt 5.3.1 与 Open Inventor 9.4.1 配合使用时出错 visual2013: C2371: "GLdouble redefinition"
- 使用"auto"关键字时"redefinition"错误更改为"differs in levels of indirection"
- 如何处理"class type redefinition"
- "Error: Redefinition of Class" - 但没有重新声明
- 如何解决类构造函数中的"redefinition of default parameter"
- MSVC错误C2371 "redefinition; different basic types",除了我没有看到我在哪里重新定义任何东西