[英]stdafx.h to header files
我有MyClass.cpp
和MyClass.h
文件。 由于MyClass.cpp
具有#include "MyClass.h"
,因此将stdafx.h
放入MyClass.h
。 编译期间出现错误:
寻找预编译的标头时,文件意外结束。 您是否忘记在源中添加“ #include“ stdafx.h””?
为什么? 如果MyClass.cpp
包括MyClass.h
它应该包括的所有行MyClass.h
和这些行包含stdafx.h
。
是否在.h文件中放入#include "stdafx.h"
没关系。 编译器不在乎。 它希望将#include "stdafx.h"
作为.cpp文件的第一行,除非您将“ Not using precompiled headers”(不使用预编译头文件)用作源文件的编译器选项。推理与预编译头文件有关。 我不能提供真正的技术解释,但只要这样做就能使生活更轻松。
如果要预编译MyClass.h
,则是另一种方法。
MyClass.h
不包含stdafx.h
stdafx.h
包括MyClass.h
MyClass.cpp
包含stdafx.h
作为第一个指令。 为了代码清晰起见,它可能还包含MyClass.h
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.