【发布时间】:2015-07-31 19:02:32
【问题描述】:
根据here找到的配方,我写了以下内容:
void printInt(int a) {std::cout << a << std::endl;}
template <typename... Args>
void f(const Args &... args) {
auto temp = {(printInt(args), void(), 0)...};
auto a = temp; temp = a;
}
两个问题:
这个语法是什么意思:
{(printInt(args), void(), 0)...}?我添加了
auto a = temp; temp = a;行,以免收到有关未使用变量temp的警告。有没有更好的办法?
经过回复和cmets的解释,剩下的唯一问题是:为什么C++不允许这样做:
template <typename... Args>
void f(const Args &... args) {
printInt(args)...;
}
在引用的帖子中提出了这个问题,但没有得到任何答案。
【问题讨论】:
标签: c++ templates c++11 variadic-templates