小编use*_*596的帖子

C++ 11非类型模板参数包扩展

在使用C++ 11模板参数包时,我想出了以下代码:

#include <cstdio>

static void testFunc(int i1, int i2) {
    printf("testFunc(%d, %d)\n", i1, i2);
}

template <size_t... Indices> void wrapper() {
    testFunc(Indices...);
}

int main(int argc, char *argv[]) {
    wrapper<1, 2>();    
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

尝试使用g ++ 4.8.2编译它会导致 "too few arguments to function ‘void testFunc(int, int)’"错误.

这是无效的C++还是g ++还没有实现这种非类型模板参数包的使用?

c++ c++11 g++4.8

12
推荐指数
1
解决办法
299
查看次数

标签 统计

c++ ×1

c++11 ×1

g++4.8 ×1