Check if keyword exists in C ++

I compiled a C ++ program that uses the C ++ keyword to override.

I compiled it successfully in Visual Studio 2010, but now I need to compile it in g ++. Only g ++ 4.6 is available (and you need g ++ 4.7 to support "overriding").

The real solution is to install g ++ 4.7 (what is happening now), but it made me think. Is there a compile time check to see if a keyword is supported?

I tried:

#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 

This does not work because "overriding" is not a symbol.

I would like something more general than just checking the compiler version to see if this is one of those that support the keyword. How can this be done, if at all?

+2
c ++
source share
1 answer

I do not know how to check certain keywords from the program. The best I can offer is to check out special predefined macros for specific versions of compilers / compilers or language / language versions.

For the first there

 #if defined __GNUC__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) 

For the latter there

 #if __cplusplus >= 201103L 
+2
source share

All Articles