Как я могу получить эту шаблонную функцию, чтобы вывести тип шаблона?C++

Программы на C++. Форум разработчиков
Anonymous
Как я могу получить эту шаблонную функцию, чтобы вывести тип шаблона?

Сообщение Anonymous »

Есть обходные пути, о которых я могу подумать, например, объявление о лямбде выше, но я просто хочу, чтобы он так работал. < /p>
template
void getListOfKeyNames(filter_t&& filter = [](int) { return true; });

int main()
{

getListOfKeyNames();
}
< /code>
Но я получаю ошибку: < /p>
note: candidate template ignored: couldn't infer template argument 'filter_t'
< /code>
Я пытался сделать это: < /p>
template
void getListOfKeyNames(filter_t&& filter = filter_t());

int main()
{

getListOfKeyNames();
}
< /code>
Но я получаю ошибку: < /p>

error: function 'getListOfKeyNames' is used
but not defined in this translation unit, and cannot be defined in any
other translation unit because its type does not have linkage

I can understand the first one won't be deduced, I guess because of deduction rules? But the second one is being explicit, why won't at least that one work? I tried on Clang and GCC.

Подробнее здесь: https://stackoverflow.com/questions/794 ... plate-type

Вернуться в «C++»