Is it possible to redefine a c++ keyword using #define?
#ifdef int
#undef int
#define int 2
#endif
int main(){
//Do something with int
}
I
Is it possible? Yes. Is it good style? Absolutely not.
The preprocessor is not aware of C/C++ keywords, it only knows about preprocessor tokens and just does strict text replacement.
Your example is resulting in an error because you're #undef
ing it. Once you undefine it, it reverts to its previous behavior.
The only valid use I know of for doing something like this is to work around a bug in an old compiler, and that compiler is no longer relevant these days.