不能将可变参数传递给嵌套可变模板调用
Cannot Pass Variable Args to Nested Variadic Template Call
编译器:TDM-GCC 5.1.0 (SJLJ Unwinding)
我有一个问题传递变量数量的类型参数到静态可变模板函数内部的模板方法调用。我已经尝试了所有的语法变化,但它无法编译,所以我只能假设我做错了。
设置如下:
#include <iostream>
template <class T>
struct Foo
{
template <class...>
static void test()
{
std::cout << "Foo<T>::test<...>() called.";
}
};
template <class T, class... Args>
void bar()
{
Foo<T>::test<Args...>(); //error happens here
}
int main()
{
bar<int, int>();
}
这给出了编译错误:expected primary-expression before '...' token
.
我认为包扩展看起来像Args...
,但这似乎不工作在这里。
你需要告诉解析器依赖的test
是一个模板:
template <class T, class... Args>
void bar()
{
Foo<T>::template test<Args...>(); //error happens here
^^^^^^^^^
}
演示相关文章:
- 如何从另一个嵌套类中调用某个封闭类的嵌套类的函数指针成员的值?
- 通过 id 访问 QML 插槽中的嵌套对象(从 c++ 调用)
- 为什么我需要三个嵌套的大括号来调用赋值运算符,将const引用到二维数组
- 如何从嵌套在命名空间中的类调用成员函数?
- 为什么使用线程池时嵌套调用 boost::async 会阻塞?
- 在C 中,为什么在嵌套的unordered_map上调用函数需要移动构造函数
- 如何使用new()在嵌套类中调用方法
- 嵌套文件夹调用的segfault
- C++ 为什么运算符>会中断嵌套的运算符()调用?
- 嵌套模板类调用模板功能
- C++ 嵌套构造函数调用问题
- 嵌套asio调用在__throw_bad_function_call()中结束
- 使用泛型函数调用打印结构的所有嵌套成员变量
- 嵌套调用中的数组运算符 (->) 重载
- 嵌套的循环调用类成员函数
- 从嵌套结构调用受保护的基类函数
- C++调用嵌套模板类析构函数
- 从外部类C++正确调用嵌套类中的函数
- 如何调用嵌套类的构造函数
- Ltrace:调用嵌套错误