# C++: error: call of overloaded 'f(int)' is ambiguous

**Code:** `call of overloaded is ambiguous` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang

Two or more overloads fit equally well, so the compiler refuses to guess which function you meant.

## 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 `0` or `NULL` where both pointer and integer overloads exist
- `using namespace` bringing two same-named functions into scope
- Constructors taking different arithmetic types
- Default arguments making two overloads equally viable

## Quick fix

1. Cast or use a literal suffix (`5L`, `5.0f`) so one overload matches exactly
2. Use `nullptr` instead of `0`/`NULL`
3. Qualify the call (`ns::f(x)`) or remove the conflicting `using`

## Detailed fix by platform

### C++

1. Add an exact overload for the argument type you pass, or call `f(static_cast<long>(x))`
2. Prefer one template or `std::string_view` instead of many near-identical overloads

## Code examples

### int matches long and double equally

```cpp
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

1. **Candidates** — Which overloads are listed under the error?
2. **Argument** — Exact type of the argument?
3. **Namespaces** — Any using-directive adding more overloads?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/ambiguous-overload)
