Why do I need to include the precompiled header in all the files in C++?

拟墨画扇 提交于 2019-12-08 03:17:08

问题


If I don't include the stdafx even in an empty .cpp, I get this error

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

Why do I need to include it even in dummy files?


回答1:


If you use them, then you must include them. But you can turn them off in the project properties.

However, the recommended way to use them is to "Force Include" the PCH from the command line, so that the file itself doesn't contain the PCH. That way the source file can be compatible with other systems.




回答2:


You can disable precompiled headers per translation unit (in the properties for a given CPP file). You can probably do it per project too, if you're willing to explore the configuration GUI. Not all project types specify a PCH either; its just the standard Microsoft Way.

I've never encountered them outside of Microsoft land, so "in C++" is a little over general!



来源:https://stackoverflow.com/questions/11052217/why-do-i-need-to-include-the-precompiled-header-in-all-the-files-in-c

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