C++: error: expected primary-expression before ')' token
The parser expected a value or expression and found a token that cannot start one — often a type name passed where a value belongs.
expected primary-expression beforeexpected primary-expression before ')' tokenexpected primary-expression before 'int'expected expression Meaning
Typical triggers: passing a type to a function (foo(int)), an empty argument, a stray comma or ), or a macro that expands to nothing. GCC names the unexpected token in the message, so look at what precedes it.
Common causes
- A type name used where a value is expected (for example
sizeof(x)written assize(int x)) - Missing argument between commas or before
) - Trailing comma in an argument or initializer list
- Macro that expands to an empty expression
- Mixing up declaration syntax and a function call
⚡ Quick fix
- Check the arguments of the call at the reported column
- Remove stray commas and extra
) - Pass a variable or literal, not a type
Detailed fix by platform
GCC / Clang
- Expand macros to see the real code:
g++ -E main.cpp | lessand search near the reported line
Code examples
Type passed instead of a value
int square(int n) { return n * n; }
int main() {
// int r = square(int); // error: expected primary-expression before 'int'
int r = square(5);
return r;
}How to diagnose
- Token — Which token does the message name?
- Arguments — Are all argument slots filled?
- Macros — Does a macro expand to nothing?
🔧 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