问题
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