上級 › テンプレートの型推論失敗で no matching function になる原因 › パターン5
テンプレートの型推論失敗で no matching function になる原因
テンプレート関数の2つの引数に異なる型を渡したときに出るエラーです。
1 #include <iostream> 2 template <typename T> 3 T minOf(T a, T b) { 4 return a < b ? a : b; 5 } 6 int main() { 7 std::cout << minOf(7, ___) << std::endl; ^ 8 return 0; 9 }
main.cpp:7:23: error: no matching function for call to 'minOf(int, double)'
空欄を埋めてコンパイル・実行を通す
7はint、2.5はdoubleで型が異なるため、テンプレートの型推論に失敗します。
次の問題