Skip to content

/errors/cpp/no-matching-function-for-call-to

C++ error: no matching function for call to

The commands on this page have not been executed by our verification runner yet.updated
tool
C++
exit code
1
versions
GCC, Clang
os
linux, macos, windows

error: no matching function for call to 'f(...)' means the compiler found functions named f, but none of them can be called with the argument types you passed. The error line shows the call as the compiler sees it, with the argument types; the note: candidate: lines below list every overload it considered and why each failed (wrong number of arguments, no conversion from one type to another, const mismatch). Change the arguments to match a candidate, or add or fix the overload.

The message appears for overloaded functions, constructors and templates. When there is only one candidate, GCC usually reports a more specific error instead, such as could not convert or cannot bind non-const lvalue reference.

Example

main.cpp
#include <algorithm>

struct Point {
    Point(int x, int y) : x(x), y(y) {}
    int x, y;
};

int main() {
    Point p;                     // no constructor takes zero arguments
    auto m = std::max(1, 2.0);   // int and double: no single T can be deduced
}

GCC reports one error per call. For Point p; the message is no matching function for call to 'Point::Point()', followed by notes for the candidates Point(int, int) and the implicit copy and move constructors, each with the reason it does not fit. For std::max(1, 2.0) the notes say that template argument deduction found conflicting types for the parameter (int and double).

Fixes

cpp
#include <algorithm>

struct Point {
    Point() = default;                    // or give the members default values
    Point(int x, int y) : x(x), y(y) {}
    int x = 0, y = 0;
};

int main() {
    Point p;
    Point q{1, 2};
    auto m = std::max<double>(1, 2.0);    // explicit template argument
    auto n = std::max(1.0, 2.0);          // or arguments of the same type
}

Common patterns

CallWhy it failsFix
std::max(1, 2.0)Deduction gives int and double for one Tstd::max<double>(1, 2.0)
Point p; with only Point(int, int)No default constructorAdd Point() = default or default member values
std::vector<Point> v(3)Needs a default constructorAdd Point() or use reserve and emplace_back
std::make_unique<Point>()Forwards to a constructor that does not existPass the constructor arguments: std::make_unique<Point>(1, 2)
Overloads f(int) and f(std::string) called as f(nullptr)No overload accepts the argumentAdd an overload or convert the argument

Sources