当前位置: 代码迷 >> 综合 >> 记录一个C++头文件包含顺序的小bug
  详细解决方案

记录一个C++头文件包含顺序的小bug

热度:21   发布时间:2023-11-01 09:17:05.0
// A simple program that computes the square root of a number
#include <cmath>
#include <iostream>
#include <string>
#include "TutorialConfig.h"#ifdef USE_MYMATH
#include "MathFunctions.h"
#endif

如上代码,由于“USE_MYMATH”的宏定义在“TutorialConfig.h”中,所以一定要先引入“TutorialConfig.h”的头文件,再进行“USE_MYMATH”的宏定义判断。

否则宏定义的判断将会失效,即如果将宏定义判断代码段放在最开头,总会被判定为未定义

  相关解决方案