can a #define “overwrite” a const variable or vice versa? Or will it lead to a compiler error?
//ONE
#define FOO 23
const int FOO = 42;
//TWO
const int FOO = 42;
#define FOO 23
What value will FOO have in both cases, 42 or 23?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First one will give compilation error. Macros are visible from the point of their definition.
That is, first one is equivalent to:
And second one is this:
Since macros are dumb, in C++
constandenumare preferred over macros. See my answer here in which I explained why macros are bad, andconstandenumare better choices.