【发布时间】:2018-10-22 11:56:37
【问题描述】:
有没有什么办法可以让这段代码在不使用va_list的东西的情况下按预期编译和工作?
#include <iostream>
void fct(void)
{
std::cout << std::endl;
}
void fct(int index, int indexes...)
{
std::cout << index << ' ';
fct(indexes); //or fct(indexes...); ?
}
int main(void)
{
fct(1, 2, 3, 4, 5, 6, 7);
return 0;
}
【问题讨论】:
-
您是否考虑过将
fct设为可变参数模板函数? -
这将如何解决我的问题?这不会使事情复杂化吗?到目前为止,我想要实现的目标似乎非常简单。
-
事实是,我不能在这里使用可变参数模板,因为我已经这样做了。上面的代码非常简化以解决我的问题的核心,但我正在处理的真实代码有一个 std::size_t 可变参数模板。我想在没有模板的情况下解决这个问题。
-
我不确定我是否遵循。你为什么不能把它做成一个模板?
-
@cantordust 我在这里提出了我的问题:stackoverflow.com/questions/50307095/…
标签: c++ parameter-passing c++17 ellipsis variadic