The problem with the inclusion of protection

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

warning C4603: '_MAPTEST_H': macro not defined or definition different after using precompiled header

Add macro to precompiled header instead of definition here

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

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

but when I add a precompiled header before the defender is turned on, no warnings or errors occur. What is the reason for this?

+5
source share
2 answers

Two issues I can think of:

  • According to this , Visual C ++ will not compile anything before the line you include in stdafx.h— so that the line should be the first in the file. If you place it after defining a macro, it will be skipped, hence the errors you see.

  • Identifiers starting with a leading underscore and an uppercase letter (or double leading underscores) are reserved, which can cause a name conflict. see this answer for more details.

+17
source

Try opening stdafx.cpp and add a macro definition! I hope your problem is resolved.

+2
source

All Articles