检查c++中是否存在Keyword
Check if Keyword Exists in C++
我正在编译一个使用c++关键字"override"的c++程序。
我在Visual Studio 2010中成功编译了它,但现在我需要在g++上编译它。只有g++ 4.6可用(你需要g++ 4.7来支持"override")。
真正的解决方案是安装g++ 4.7(现在正在发生),但它让我思考。是否有编译时检查以查看是否支持关键字?
我试着:
#ifndef override
#define override
#ifdef BUILD_WINDOWS
#pragma message("The "override" keyword is not supported on this compiler! Ignoring it!")
#else
#warning "The "override" keyword is not supported on this compiler! Ignoring it!"
#endif
#endif
这行不通,因为"override"不是一个符号。
我想要一些更一般的东西,而不是简单地检查编译器版本,看看它是否是支持关键字的一个。如果有的话,该如何做到这一点呢?
我知道没有办法从程序中检查特定的关键字。我能提供的最好的是检查特定编译器/编译器版本或语言/语言版本的特殊预定义宏。
对于前者,有
#if defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7))
对于后者,有
#if __cplusplus >= 201103L
相关文章:
- C++模板来检查友元函数的存在
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- g++ 说函数不存在,即使包含正确的标头
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 有了gcc,是否可以链接库,但前提是它存在
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- C++Builder中的OnClick事件签名存在问题
- 如何正确地将分支添加到已存在的树中
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 如何检查QList中是否存在值
- 根据某个函数是否存在启用模板
- 如何将分支添加到已存在的TTree:ROOT
- 地图计数确实很重要,或者只是检查是否存在
- 通用C++/Python 多语言的存在
- 检查c++中是否存在Keyword