C++: error: call of overloaded 'f(int)' is ambiguous
Two or more overloads fit equally well, so the compiler refuses to guess which function you meant.
call of overloaded is ambiguouserror: call of overloaded 'f(int)' is ambiguousambiguous call to overloaded functionreference to 'count' is ambiguousreference to 'distance' is ambiguous Meaning
Overload resolution ranks implicit conversions. With f(long) and f(double), calling f(5) converts int to either and ties. Ambiguity also appears with nullptr vs 0, string literals vs bool, and ADL finding the same name in two namespaces.
Common causes
- Overloads that differ only by numeric types and an argument needing conversion to both
- Passing
0orNULLwhere both pointer and integer overloads exist using namespacebringing two same-named functions into scope- Constructors taking different arithmetic types
- Default arguments making two overloads equally viable
⚡ Quick fix
- Cast or use a literal suffix (
5L,5.0f) so one overload matches exactly - Use
nullptrinstead of0/NULL - Qualify the call (
ns::f(x)) or remove the conflictingusing
Detailed fix by platform
C++
- Add an exact overload for the argument type you pass, or call
f(static_cast<long>(x)) - Prefer one template or
std::string_viewinstead of many near-identical overloads
Code examples
int matches long and double equally
void f(long v);
void f(double v);
int main() {
// f(5); // error: call of overloaded 'f(int)' is ambiguous
f(5L); // exact match for long
f(5.0); // exact match for double
}How to diagnose
- Candidates — Which overloads are listed under the error?
- Argument — Exact type of the argument?
- Namespaces — Any using-directive adding more overloads?
🔧 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
- Assertion failed C/C++: Assertion `x > 0' failed. Aborted (core dumped) — assert() condition was false
- C2065 MSVC: error C2065: 'x': undeclared identifier
- comparison of integers of different signs C/C++: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' [-Wsign-compare]
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