相关疑难解决方法(0)

可以在模板外使用c ++ 11参数包吗?

我想知道我是否可以使用由明确指定的单一类型组成的参数包.例如,像这样:

#include <iostream>

using namespace std;

void show() { }

template<typename First, typename... Rest>
void show(First f, Rest... rest)
{
    cout << f << endl;
    show(rest...);
}

void foo(int f, int... args) // error
{
    show(f, args...);
}

int main()
{
    foo(1, 2, 3);
}
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是定义foo().使用OS X clang ++版本5(llvm 3.3svn)我收到错误error: type 'int' of function parameter pack does not contain any unexpanded parameter packs.

当然,我可以通过更改foo()为函数模板来编译它:

template<typename... Args>
void foo(int f, Args... args)
{
    show(f, args...); …
Run Code Online (Sandbox Code Playgroud)

c++ templates c++11

24
推荐指数
2
解决办法
8004
查看次数

标签 统计

c++ ×1

c++11 ×1

templates ×1