I have the following code:
#include <iostream>
template <typename... Args>
void f(int a, int b, Args... args) {
std::cout << b << '\n';
f(a, args...);
}
void f(int, int b) {
std::cout << b << '\n';
}
int main() {
f(1, 2);
//f(1, 2, 3);
}
While f(1, 2) compiles, f(1, 2, 3) does not. From the error message produced by the compiler, I see that f<> is being instantiated somehow. Within the instantiation, the call f(a) is made and thus the error. What makes the compiler not to use f(int, int) but try to instantiate f<>(int, int) during the process of parsing the call f(1, 2, 3)?
Aucun commentaire:
Enregistrer un commentaire