How do I fix class template has already been defined?

青春壹個敷衍的年華 提交于 2019-12-11 18:58:46

问题


I am implementing ZipArchive library into my project, and I fought with it for over an hour getting it setup right to stop all the linker errors. But now I still have this left over and I am not sure of the best approach to fix it, could use some help.

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'

回答1:


Both MS' ATL/MFC headers and the HL2 SDK contain a class template CThreadLocal.

If you'd include those in the right order, i.e. ATL/MFC headers first (or the headers which include them), then the HL2 SDK headers, the HL2 SDK should handle that problem via an #ifndef __AFXTLS_H__.




回答2:


C++ Templates hints:

  • EVERYTHING must be in the header file ( .h)
  • to solve redefinition just put your code into:
#ifndef __MY_CODE_eg
#define __MY_CODE_eg

      // your code
      // here.

#endif


来源:https://stackoverflow.com/questions/2346879/how-do-i-fix-class-template-has-already-been-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!