如何修复类模板已定义?

时间:2010-02-27 09:51:11

标签: c++ class templates defined

我正在将ZipArchive库实现到我的项目中,并且我用它进行了一个多小时的斗争,让它正确设置以停止所有链接器错误。但现在我仍然遗留下来,我不确定解决它的最佳方法,可以使用一些帮助。

C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxtls_.h(199) : error C2953: 'CThreadLocal' : class template has already been defined
c:\dev-mms\hl2sdk-ob-valve\public\tier0/threadtools.h(283) : see declaration of 'CThreadLocal'
C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxtls_.h(202) : warning C4005: 'THREAD_LOCAL' : macro redefinition
c:\dev-mms\hl2sdk-ob-valve\public\tier0/threadtools.h(71) : see previous definition of 'THREAD_LOCAL'

2 个答案:

答案 0 :(得分:3)

C ++模板提示:

  • 一切都必须在头文件(.h)
  • 解决重新定义只需将您的代码放入:
#ifndef __MY_CODE_eg
#define __MY_CODE_eg

      // your code
      // here.

#endif

答案 1 :(得分:2)

MS'ATL / MFC标头和HL2 SDK都包含类模板CThreadLocal

如果您按正确的顺序包含它们,即首先是ATL / MFC标头(或包含它们的标头),那么HL2 SDK标头,HL2 SDK应该通过#ifndef __AFXTLS_H__处理该问题。