How do I fix class template has already been defin

2019-09-13 01:43发布

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'

2条回答
女痞
2楼-- · 2019-09-13 01:48

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
查看更多
等我变得足够好
3楼-- · 2019-09-13 01:51

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__.

查看更多
登录 后发表回答