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.
template argument deduction/substitution failedcouldn't deduce template parameterdeduced conflicting types for parameterno matching function for call to templatecandidate template ignored: could not match 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
requiresclause or enable_if rejected the type
⚡ Quick fix
- Pass explicit template arguments:
std::max<double>(1, 2.5) - Cast arguments to the same type
- Read the "candidate" note to see which parameter failed
Detailed fix by platform
C++
auto m = std::max<double>(a, b);for mixed int/double- With C++17 you can often use class template argument deduction (
std::pair p{1, 2.5};)
Code examples
Conflicting deduction
#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
- Arguments — Do all arguments of one template parameter have the same type?
- Return — Does the type appear in the parameters?
- 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:
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