相关疑难解决方法(0)

Variadic模板包扩展

我正在尝试学习可变参数模板和函数.我无法理解为什么这段代码不能编译:

template<typename T>
static void bar(T t) {}

template<typename... Args>
static void foo2(Args... args)
{
    (bar(args)...);
}

int main()
{
    foo2(1, 2, 3, "3");
    return 0;    
}
Run Code Online (Sandbox Code Playgroud)

当我编译它失败时出现错误:

错误C3520:'args':必须在此上下文中扩展参数包

(在功能上foo2).

c++ templates variadic-templates c++11

69
推荐指数
4
解决办法
4万
查看次数

标签 统计

c++ ×1

c++11 ×1

templates ×1

variadic-templates ×1