如何使用参数包调用函数的重载版本?这大概是我想做的:
void foo(int x=5) {
// Call foo<Args...>(x) here
}
template <typename... Args>
void foo(int x, Args&&... args) {
}
那可能吗?还是我需要不同的函数名?
最佳答案
您可以通过显式指定模板参数来调用模板版本。如果没有要指定的模板参数,则可以指定空列表。例如
template <typename... Args>
void foo(int x, Args&&... args) {
}
void foo(int x=5) {
foo<>(x);
}
关于c++ - C++:使用参数包显式调用函数重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59349574/