首页 > 解决方案 > 参数包提取

问题描述

我有一个函数 2,可以使用或不使用第二个参数 == char 来调用它。如果是这样,我想修改那个字符参数。

给定

void function1_caller(int x) { 
    char ws=7; 
    function2_modifyArg(x, ws); 
}

这有效:

template <typename ... WS> 
void function2_modifyArg(int x, WS ... ws) { 
    function3_end(x, ws ...);
}

简单地放在括号中,已经不起作用了:

template <typename ... WS> 
void function2_modifyArg(int x, WS ... ws) { 
    function3_end(x, (ws ... )); 
}

这会导致以下错误:

Syntax error: unexpected token '...', expected declaration

实际上在这里我想修改参数,但我当然得到相同的

Syntax error: unexpected token '...', expected declaration
template <typename ... WS> 
void function2_modifyArg(int x, WS ... ws) { 
    function3_end(x, (ws ... / 3));
}

template <typename ... WS> 
void function3_end(int x, WS ... ws) {};

标签: c++parameter-pack

解决方案



推荐阅读