0

我有一个函数 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) {};
4

2 回答 2

2
于 2021-10-02T06:23:48.240 回答
0

You don't need the parenthesis you just need to put the operation you want to do before the pack expansion:

template <typename ... WS> 
void function2_modifyArg(int x, WS ... ws) { 
    function3_end(x, ws / 3 ...);
}
于 2021-10-02T06:23:49.527 回答