Привет, простите, если простой вопрос, я тут с некоторым отставанием пытаюсь освоить с++17...
Вот такой код
template<class F>
void test(F f) {
f(1, 2);
}
template<class T>
auto func(T a, T b) {
return a + b;
}
int main() {
test([](auto x, auto y) { func(x, y);}); // компилируется
test(func); // не компилируется
}
gcc выдаёт
test.cpp: In function ‘int main()’:
test.cpp:15:14: error: no matching function for call to ‘test(<unresolved overloaded function type>)’
15 | test(func);
| ^
test.cpp:2:6: note: candidate: ‘template<class F> void test(F)’
2 | void test(F f) {
| ^~~~
test.cpp:2:6: note: template argument deduction/substitution failed:
test.cpp:15:14: note: couldn’t deduce template parameter ‘F’
15 | test(func);
| ^
Если func сделать простой функцией, без шаблона, всё работает. С шаблоном только через обёртку из лямбды.
Так и должно быть? Можно как-то просто объяснить, почему?