stdafx.h 到头文件

编程入门 行业动态 更新时间:2024-10-08 10:57:04
本文介绍了stdafx.h 到头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有 MyClass.cppMyClass.h 文件.由于 MyClass.cpp#include "MyClass.h" 我把 stdafx.h 放到 MyClass.h.在编译过程中出现错误:

I have MyClass.cpp and MyClass.h files. Since MyClass.cpp has #include "MyClass.h" I put stdafx.h to MyClass.h. During compile I got error:

在查找预编译头时出现意外的文件结尾.您是否忘记将#includestdafx.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.

Why? If MyClass.cpp includes MyClass.h it should include all lines of MyClass.h and these lines contain stdafx.h.

推荐答案

是否将 #include "stdafx.h" 放在 .h 文件中并不重要.编译器不在乎.它希望将 #include "stdafx.h" 视为 .cpp 文件的第一行,除非您将不使用预编译头"作为源文件的编译器选项.推理有与预编译头有关.我无法真正提供技术性解释,但简单地这样做会让生活更轻松.

It doesn't matter if you put #include "stdafx.h" inside your .h file. The compiler doesn't care. It wants to see #include "stdafx.h" as the first line of your .cpp file, unless you have "Not using precompiled headers" as a compiler option for your source file.. The reasoning has to do with precompiled headers. I cannot really offer a technical explanation, but simply doing it that way will make life easier.

这篇关于stdafx.h 到头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-27 15:11:27,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   stdafx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!