作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 MyClass.cpp
和 MyClass.h
文件。因为 MyClass.cpp
有 #include "MyClass.h"
我把 stdafx.h
放到 MyClass.h
中。编译期间出现错误:
unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
为什么?如果 MyClass.cpp
包含 MyClass.h
,它应该包含 MyClass.h
的所有行,并且这些行包含 stdafx.h
.
最佳答案
将#include "stdafx.h"
放在.h 文件中并不重要。编译器不在乎。它希望将 #include "stdafx.h"
视为 .cpp 文件的第一行,除非您将“不使用预编译头文件”作为源文件的编译器选项。推理有与预编译头有关。我无法真正提供技术解释,但简单地这样做会让生活更轻松。
关于c++ - stdafx.h 到头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25451219/
我是一名优秀的程序员,十分优秀!