Summary

The expected unqualified-id before numeric constant error appears when a macro such as #define MAX_SIZE 100 expands in a spot where a variable, member or function name belongs, leaving the number (100) where a name should be. Use a name that differs from the macro, replace the macro with a constexpr constant, or, if you really must, #undef it before the clash.

Running into an expected unqualified-id before numeric constant error on a perfectly normal-looking member declaration can be confusing. This post uses code and real compiler output reproduced on 2026-10-21 (KST) with g++ (Debian 14.2.0-19) 14.2.0.

One-line answer: A macro (#define MAX_SIZE 100) expands where a name belongs and leaves a number behind. Fix it by renaming, using constexpr, or using #undef.

What is the “expected unqualified-id before numeric constant” error?

One-line answer: It means a numeric constant showed up where a name (identifier) was expected. An unqualified-id is a name without a qualifier such as Foo::.

Here is bad.cpp, where a member has the same name as a macro.

#define MAX_SIZE 100

struct Config {
    int MAX_SIZE = 10;   // 매크로 이름과 같은 멤버 이름
};

int main() {
    Config c;
    return c.MAX_SIZE;
}

This is the real output of g++ -std=c++17 -c bad.cpp (exit code 1).

$ g++ -std=c++17 -c bad.cpp
bad.cpp:1:18: error: expected unqualified-id before numeric constant
    1 | #define MAX_SIZE 100
      |                  ^~~
bad.cpp:4:9: note: in expansion of macro ‘MAX_SIZE’
    4 |     int MAX_SIZE = 10;   // 매크로 이름과 같은 멤버 이름
      |         ^~~~~~~~
bad.cpp: In function ‘int main()’:
bad.cpp:1:18: error: expected unqualified-id before numeric constant
    1 | #define MAX_SIZE 100
      |                  ^~~
bad.cpp:9:14: note: in expansion of macro ‘MAX_SIZE’
    9 |     return c.MAX_SIZE;
      |              ^~~~~~~~
bad.cpp:9:14: error: expected ‘;’ before numeric constant
    9 |     return c.MAX_SIZE;
      |              ^
      |              ;

Why do macro name clashes cause it?

One-line answer: The preprocessor replaces the macro name with its text, literally, before compilation.

The compiler never sees the name MAX_SIZE; it only sees the preprocessed result. Running g++ -E -P bad.cpp shows it.

$ g++ -E -P bad.cpp
struct Config {
    int 100 = 10;
};
int main() {
    Config c;
    return c. 100;
}
  • Before: int MAX_SIZE = 10; → after: int 100 = 10;
  • Before: return c.MAX_SIZE; → after: return c. 100;
  • A number sits where a name should be, which gives “expected unqualified-id before numeric constant”.

Here is how to read the output.

  • The error points at bad.cpp:1:18, the 100 in #define MAX_SIZE 100. That is where the substituted number was written.
  • The note: in expansion of macro ‘MAX_SIZE’ right below it shows where the macro was actually used (4:9 and 9:14). That is the side you need to fix.
  • The third message, expected ‘;’ before numeric constant, looks like a follow-on error from c. 100.

Preprocessor flow where macro MAX_SIZE expands to 100 in the member declaration and c.MAX_SIZE access, yielding int 100 = 10 and return c. 100

How do I fix it?

One-line answer: Use a different name, replace the macro with constexpr, or #undef it before the clash.

  1. Rename: change the member to something different from the macro, such as max_size.
  2. Use constexpr: write constexpr int kMaxSize = 100; instead of a macro. A constant follows normal scoping rules, so no text substitution happens.
  3. #undef: put #undef MAX_SIZE before the clashing declaration. Be careful about order, because headers included later may still need that macro.
  4. Naming rule: keep macros in ALL_CAPS and avoid all-caps names for ordinary variables and members.

This is good.cpp with fixes 1 and 2.

#define MAX_SIZE 100

struct Config {
    int max_size = 10;   // 매크로와 다른 이름 사용
};

constexpr int kMaxSize = 100;  // 매크로 대신 constexpr

int main() {
    Config c;
    return c.max_size + kMaxSize - MAX_SIZE;
}
$ g++ -std=c++17 good.cpp -o good && ./good; echo $?
10

This is undef.cpp with fix 3.

#define MAX_SIZE 100

#undef MAX_SIZE
struct Config {
    int MAX_SIZE = 10;   // 매크로 이름과 같은 멤버 이름
};

int main() {
    Config c;
    return c.MAX_SIZE;
}
$ g++ -std=c++17 -c undef.cpp
$ echo $?
0

good.cpp compiled and ran with exit code 10, and undef.cpp compiled successfully (exit code 0).

For another C++ pitfall, see our C++ explicit post.

How do I find a macro that comes from a header?

One-line answer: Read the file:line in the note, then search the g++ -E output for that name.

  • If you did not write the macro yourself, start with the location given by note: in expansion of macro.
  • Save the g++ -E output to a file and search for the suspect name to see the substituted result directly. To view transformed code visually, see our C++ Insights post.
  • A well-known example is min/max in Windows headers. Microsoft Learn’s “max macro (Minwindef.h)” page shows #define max(a, b) (((a) > (b)) ? (a) : (b)) (documentation). Because it is a function-like macro, names such as std::max can be affected too.
  • It is also common practice to put #define NOMINMAX before including <windows.h> so those macros are never defined.
  • Alternatively, wrap the name in parentheses when calling it: (std::max)(a, b).
  • If you need to debug further, see our gdb post.

What are the frequently asked questions?

One-line answer: These three questions come up most often.

Q1. Can the same message appear without a macro?

Yes. For example, writing a statement such as return 1; outside any function makes the same g++ 14.2.0 print error: expected unqualified-id before ‘return’. The difference is the ending: it is not “numeric constant”. In that case, check where the statement is placed rather than looking for a macro.

Q2. Does it happen with enum or constant names too?

Yes. It happens in any position where an identifier can appear (variables, members, functions, enum values and so on), because the substitution works the same way.

Q3. What if I really have to use a macro?

Add a project prefix such as MYLIB_MAX_SIZE to reduce the chance of clashing with other names.

One-line answer: Our posts on C++ explicit, C++ Insights and gdb.

What are the sources?

One-line answer: My own GCC run and the Microsoft Learn page.