I don’t understand why the following code won’t compile:
#include <iostream>
#define SHORT_NAME 4;
int func(int arg)
{
return arg;
}
int main()
{
return func(SHORT_NAME); // Error: expected a ')'
}
Should I be using const int SHORT_NAME = 4 on line 2 instead?
Remove the semi-colon from the macro
SHORT_NAMEas after preprocessing it is expanded to:Or use
const intas you suggest in the question. See "static const" vs "#define" vs "enum" for a discussion on macros vsconst.