template argument deduction/substitution failed C/C++ Origin: Application & API Last updated 15 Oct 2026

C++: error: template argument deduction/substitution failed / couldn't deduce template parameter

The compiler could not work out the template arguments from your call — the arguments disagree, the type can't be deduced, or a constraint failed.

Exact message you may see template argument deduction/substitution failedcouldn't deduce template parameterdeduced conflicting types for parameterno matching function for call to templatecandidate template ignored: could not match
Seen on: C/C++ GCC Clang

Meaning

Deduction looks only at function arguments. It fails when two arguments give conflicting types (max(1, 2.5)), when the type appears only in the return type, with braced-init-lists, or when an overload or a lambda is passed where a type is expected. Specify the argument explicitly (f<int>(x)) or unify the types.

Common causes

  • Conflicting argument types for the same template parameter (int and double)
  • Template parameter appears only in the return type
  • Braced list {1,2} passed to a deduced parameter
  • Passing an overloaded function or generic lambda directly
  • A requires clause or enable_if rejected the type

⚡ Quick fix

  1. Pass explicit template arguments: std::max<double>(1, 2.5)
  2. Cast arguments to the same type
  3. Read the "candidate" note to see which parameter failed

Detailed fix by platform

C++

  1. auto m = std::max<double>(a, b); for mixed int/double
  2. With C++17 you can often use class template argument deduction (std::pair p{1, 2.5};)

Code examples

Conflicting deduction

cpp
#include <algorithm>

int main() {
    int a = 1; double b = 2.5;
    // auto m = std::max(a, b);          // error: no matching function; deduced conflicting types 'int' and 'double'
    auto m = std::max<double>(a, b);     // OK
    return static_cast<int>(m);
}

How to diagnose

  1. Arguments — Do all arguments of one template parameter have the same type?
  2. Return — Does the type appear in the parameters?
  3. Constraint — Is there a requires/enable_if?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

call of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…does not name a type — C++: error: 'string' does not name a type (C/C++)does not name a typeinvalid conversion from — C++: error: invalid conversion from 'const char*' to 'char*' [-fpermissive] (C/C++)invalid conversion fr…ISO C++ forbids comparison between pointer and integer — C++: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] (C/C++)ISO C++ forbids compa…narrowing conversion — C++: error: narrowing conversion of 'x' from 'int' to 'char' inside { } [-Wnarrowing] (C/C++)narrowing conversionneed typename before dependent name — C++: error: need 'typename' before 'T::iterator' because 'T' is a dependent scope (C/C++)need typename before …no match for 'operator' — C++: error: no match for 'operator<<' (operand types are 'std::ostream' and 'X') (C/C++)no match for 'operato…no matching function for call to — C++: error: no matching function for call to 'f(int, const char*)' (C/C++)no matching function …template …

Explore the map of this error Full error map →

🧠 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.