我可以取消定义 EXIT_SUCCESS 吗?
我想定义我自己的枚举类型:ExitType。我是这样写的:
enum ExitType{
EXIT_SUCCESS,
EXIT_FAILURE,
EXIT_OTHERTYPE
};
我有一个返回 ExitType 的函数。在某些情况下它会返回 EXIT_SUCCESS。但我收到错误消息,指出您无法从 int 转换为 ExitType。我可以为 IDE 取消定义 EXIT_SUCCESS,还是我只能使用 static_cast
?似乎引入了他们的 EXIT_SUCCESS 将与我的 EXIT_OTHERTYPE 一致的可能性,等等。
我将 Eclipse Helios 与 CDT、MinGW32 和 SDL 一起使用。所有 32 位且最新版本。
编辑:尝试使用预处理器取消定义 EXIT_SUCCESS。
#undef EXIT_SUCCESS
#undef EXIT_FAILURE
enum ExitType{
EXIT_SUCCESS,
EXIT_FAILURE,
EXIT_OTHERTYPE,
EXIT_NOEXIT
};
结果:
..\src\EventManager.cpp:12:7: 错误:从“int”到“ExitType”的转换无效
编辑 2:当我在包含
I'd like to define my own Enumerated type: ExitType. I wrote it like so:
enum ExitType{
EXIT_SUCCESS,
EXIT_FAILURE,
EXIT_OTHERTYPE
};
I have a function that returns an ExitType. On some conditions it returns EXIT_SUCCESS. But I get the error message that you can't cast from an int to an ExitType. Can I undefine EXIT_SUCCESS for my IDE, or am I stuck using static_cast<int>(EXIT_SUCCESS)
? It seems to introduce the possibility that their EXIT_SUCCESS will line up with my EXIT_OTHERTYPE, etc.
I'm using Eclipse Helios with the CDT, MinGW32 and SDL. All 32-bit, and the latest versions.
Edit: Tried undefining EXIT_SUCCESS with the preprocessor.
#undef EXIT_SUCCESS
#undef EXIT_FAILURE
enum ExitType{
EXIT_SUCCESS,
EXIT_FAILURE,
EXIT_OTHERTYPE,
EXIT_NOEXIT
};
Result:
..\src\EventManager.cpp:12:7: error: invalid conversion from 'int' to 'ExitType'
Edit 2: When I moved my undefines AFTER the inclusion of <SDL/SDL.h>, the error went away. A GREP of the SDL code doesn't turn up anything matching EXIT_SUCCESS, though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#undef EXIT_SUCCESS
应该取消定义预处理器符号EXIT_SUCCESS
,这就是我假设的情况。但只有当您确定这样做不会破坏任何东西时才这样做!#undef EXIT_SUCCESS
should undefine the preprocessor symbolEXIT_SUCCESS
, which is what I assume is going on here. But only do that if you're CERTAIN that you will not break anything by doing so!