Код:VARIADIC шаблон не компилируется
#include <iostream>
template<typename T>
void out() // line 4
{
}
template<typename T, typename... Args>
void out(T value, Args... args) // line 9
{
std::cout << value;
out(args...); // line 12
}
int main()
{
out("12345", std::endl); // line 17
return 0;
}
Строят ошибки:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -pthread -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
../main.cpp: In function ‘int main()’:
../main.cpp:17:24: error: no matching function for call to ‘out(const char [6], <unresolved overloaded function type>)’
../main.cpp:17:24: note: candidates are:
../main.cpp:4:6: note: template<class T> void out()
../main.cpp:4:6: note: template argument deduction/substitution failed:
../main.cpp:17:24: note: candidate expects 0 arguments, 2 provided
../main.cpp:9:6: note: void out(T, Args ...) [with T = const char*; Args = {}]
../main.cpp:9:6: note: candidate expects 1 argument, 2 provided
Я хочу, чтобы эта программа, чтобы дать тот же результат, как std::cout << "12345" << std::endl;
Что плохого в функции шаблона?
Вам не хватает '.' в инструкции для распаковки. Измените его на 'args ...'. – legends2k
Редактирование вопроса, есть еще сообщения с ... –
@AlexFarber Мои извинения ... – 0x499602D2