Why stdfax.h should be the first include on MFC applications?(为什么 stdfax.h 应该是 MFC 应用程序的第一个包含?)
问题描述
我想知道为什么每个 MFC 应用程序都存在这条线(这迫使 stdafx.h 成为每个文件中包含的第一个标头):
I want to know why this line exists on every MFC app (which force to make stdafx.h the first header included in every file) :
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
这种行为背后的原因是什么?
What are the reason(s) behind this behavior ?
推荐答案
只有在使用Precompiled Headers (PCH)时才会这样,以及为什么在#include "stdafx.h"之前不应该有任何东西的原因 是:
It's only true when using Precompiled Headers (PCH), and the reason why there shouldn't be anything before the #include "stdafx.h" is :
Visual C++ 不会在 #include "stdafx.h" 之前编译任何内容源文件,除非编译选项/Yu'stdafx.h' 未选中(默认情况下);它假定源代码中的所有代码,包括该行已经编译
Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled
来自 http://en.wikipedia.org/wiki/Precompiled_header
这篇关于为什么 stdfax.h 应该是 MFC 应用程序的第一个包含?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么 stdfax.h 应该是 MFC 应用程序的第一个包含?
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
