thu*_*ium 6 c++ visual-studio-2010
我正在做一些宏
#define report_msg(type,msg_str).......my_special_##type(......)
#define report_error(msg_str) report_msg(ERROR,msg_str)
Run Code Online (Sandbox Code Playgroud)
当我使用Visual Studio 2010 Express编译时,它在linux下工作完美,我看到它给出了以下错误:
error C3861: 'my_special_0': identifier not found
Run Code Online (Sandbox Code Playgroud)
原因是“ ERROR”被解释为0。当我在MSVC中使用“转到定义”时,它将转到WinGDI.h。
/* Region Flags */
#define ERROR 0
Run Code Online (Sandbox Code Playgroud)
问题是为什么包含此WinGDI.h?如何消除它而不接触代码?
解决方案1: 交换某些标头的包含顺序->繁琐的任务
解决方案2:
放入NOGDI预处理器。在Visual Studio中:项目属性->配置属性-> C / C ++->预处理程序->预处理程序定义-> add NOGDI。
说明:
保罗为我指明了正确的方向。我不使用预编译的标头,因此不包含stdafx.h。我的问题与Linux与Windows库有关。
就我而言,我使用一个库,该库为日志消息定义了常量“ ERROR”。对于时间戳记ctime.h,包含使用Windows.h/ WinGDI.h。
这就是为什么宏是邪恶的。我见过在不同标题中使用不同值定义 TRUE 和 FALSE 的情况。在任何体面的项目中,遵循标题链可能会变得乏味。尝试
#undef ERROR
#define report_msg(type,msg_str).......my_special_##type(......)
#define report_error(msg_str) report_msg(ERROR,msg_str)
Run Code Online (Sandbox Code Playgroud)
并希望在这些语句之后不需要 ERROR 的“真实”定义。
| 归档时间: |
|
| 查看次数: |
4188 次 |
| 最近记录: |