C++: error: expected unqualified-id before 'return' / before ')' token
The parser found a token where a name (declaration) was required — often a missing brace, a stray ), or a statement placed in a class body.
expected unqualified-id beforeexpected unqualified-id before 'return'expected unqualified-id before ')' tokenexpected unqualified-id before numeric constantexpected identifier or '(' Meaning
This is a catch-all syntax error that GCC emits when it expects an identifier. Missing } before a function, code placed directly in a class or at global scope, a stray semicolon after a function header, or a macro that swallowed a token are the common causes.
Common causes
- Missing or extra closing brace earlier in the file
- Executable statement written inside a class body or at file scope
- Stray
;or)after a function signature - Using a keyword or macro name as an identifier (
int new;,int maxwith amaxmacro) - Declaration of a variable with a reserved name
⚡ Quick fix
- Check braces above the error with your editor's matching
- Move statements into a function
- Rename identifiers that clash with keywords or macros (define
NOMINMAXon Windows)
Detailed fix by platform
GCC / Clang
- Compile only that file with
-fsyntax-onlyand fix the first error; later ones usually cascade
Windows
- Before including
<windows.h>add#define NOMINMAXsomin/maxare not macros
Code examples
Statement inside a class body
struct Counter {
int n = 0;
n++; // error: expected unqualified-id before '++' token
void inc() { n++; } // OK: statements belong in functions
};How to diagnose
- Position — What comes just before the reported token?
- Braces — Balanced up to this point?
- Names — Is an identifier a keyword or macro?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026