function one () принимает один пакет параметров. Функция two () принимает два. Каждый пакет ограничен для обертывания в типах a и b . Почему невозможно создать экземпляр two () < /em>? < /P>
template
struct A {};
template
struct B {};
template
void one(A ...as) {
}
template
void two(A ...as, B ...bs) {
}
int main() {
auto a = A();
auto b = B();
// Just fine
one();
one(a);
one(a, a);
// All errors
two();
two(a);
two(a, b);
}
< /code>
Пробое с GCC и Clang. < /p>
sam@wish:~/x/cpp$ gcc -std=c++0x variadic_templates.cpp
variadic_templates.cpp: In function ‘int main()’:
variadic_templates.cpp:23:7: error: no matching function for call to ‘two()’
variadic_templates.cpp:23:7: note: candidate is:
variadic_templates.cpp:11:6: note: template void two(A..., B...)
variadic_templates.cpp:24:8: error: no matching function for call to ‘two(A&)’
variadic_templates.cpp:24:8: note: candidate is:
variadic_templates.cpp:11:6: note: template void two(A..., B...)
variadic_templates.cpp:25:11: error: no matching function for call to ‘two(A&, B&)’
variadic_templates.cpp:25:11: note: candidate is:
variadic_templates.cpp:11:6: note: template void two(A..., B...)
sam@wish:~/x/cpp$ clang -std=c++0x variadic_templates.cpp
variadic_templates.cpp:23:3: error: no matching function for call to 'two'
two();
^~~
variadic_templates.cpp:11:6: note: candidate function template not viable: requires at least 1 argument, but 0 were provided
void two(A ...as, B ...bs) {}
^
variadic_templates.cpp:24:3: error: no matching function for call to 'two'
two(a);
^~~
variadic_templates.cpp:11:6: note: candidate function not viable: requires 0 arguments, but 1 was provided
void two(A ...as, B ...bs) {}
^
variadic_templates.cpp:25:3: error: no matching function for call to 'two'
two(a, b);
^~~
variadic_templates.cpp:11:6: note: candidate function not viable: requires 0 arguments, but 2 were provided
void two(A ...as, B ...bs) {}
^
3 errors generated.
Подробнее здесь: https://stackoverflow.com/questions/983 ... c-template