C++怎么替换宏定义?或者类型定义?

2025-05-14 15:22:24
推荐回答(1个)
回答(1):

二楼正解。我给解释一下吧。
假设你在head.h和 xa.cpp文件中都写了这么一条语句
:#define x 2
编译器会报错,因为重复定义了。
改正方法是在head.h 中写上
#ifndef head
#define head
///////
#define x 新数值
///////
#endif
。然后再在xa.cpp中包含head头文件就可以了