Reputation: 12983
We have a project that’s using many C++11 facilities, and we thought about this trick to make it compile on C++03.
#ifndef USE_CPP0X
# define override
#endif
As far as I know it’s forbidden to define C++ keywords, so is this legal?
Upvotes: 2
Views: 761
Reputation: 461
Even more explicit in terms of using 'override' for C++11 and above would be:
#if __cplusplus >= 201103L
#define OVERRIDE override
#else
#define OVERRIDE
#endif
The value 201103L is the standard agreed for C++11. The macro __cplusplus is sure to be defined unless you're using an ancient compiler.
Upvotes: 3
Reputation: 409462
It is somewhat frowned upon, but it's certainly possible. A better and not so frowned upon variant is to define macros in all large letter, something like
#ifndef USE_CPP0x
# define OVERRIDE
#else
# define OVERRIDE override
#endif
Then remember to use OVERRIDE
instead of override
where wanted.
Upvotes: 7