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
Как я могу иметь несколько пакетов параметров в вариационном шаблоне? ⇐ C++
Программы на C++. Форум разработчиков
1759504216
Anonymous
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.
Подробнее здесь: [url]https://stackoverflow.com/questions/9831501/how-can-i-have-multiple-parameter-packs-in-a-variadic-template[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия