头文件包含顺序问题

来源:互联网 发布:入店来源淘宝首页 编辑:程序博客网 时间:2024/05/17 03:12

错误程序:

#include <xnamath.h>#include <windows.h>#include <iostream>using namespace std;int main() {return 0;}


该程序在VS2010中编译会产生251个错误。

分析:

xnamath.h头文件中用到了FLOAT数据类型,该类型在windef.h中定义,而windows.h中包含了windef.h,但是包含的顺序导致了xnamath.h中无法识别FLOAT类型,将包含顺序反过来就对了。

#include <windows.h>#include <xnamath.h>#include <iostream>using namespace std;int main() {return 0;}

 

该错误以前从没遇到过,也花了近一个小时才找到错误。虽然是小BUD但是值得注意。