开发者

Problem with include guard

开发者 https://www.devze.com 2023-01-01 08:56 出处:网络
When I add an include guard to my header file for a Visual C++ project, it gives me the following warning and error:

When I add an include guard to my header file for a Visual C++ project, it gives me the following warning and error:

warning C4603: '_MAPTEST_H' : macro is not de开发者_Go百科fined or definition is different after precompiled header use

Add macro to precompiled header instead of defining here

.\MapTest.cpp(6) : use of precompiled header** // the precompiled header stdafx.h is included in this line

.\MapTest.cpp(186) : fatal error C1020: unexpected #endif

but when I add the precompiled header before the include guard, no warning or error is emitted. What is the reason for this?


Two problems I can think of:

  1. According to this, Visual C++ won't compile anything before the line where you include stdafx.h - so that line needs to be the very first one in the file. If you put it after the macro definition, it gets skipped, hence the errors you're seeing.

  2. Identifiers starting with a leading underscore and a capital letter (or double leading underscores) are reserved, which might be causing a name conflict. see this answer for more details.


Try opening stdafx.cpp and add your macro definition there! I hope your problem is solved

0

精彩评论

暂无评论...
验证码 换一张
取 消