vendredi 22 mai 2020

What is the difference between variadic template and ellipsis?

I know the title does no make much of a sense, but the code will explain my problem.

template<typename T>
void foo(T...) {std::cout << 'A';}

template<typename... T>
void foo(T...) {std::cout << 'B';}

int main(){  
   foo(1); 
   foo(1,2);
}

Try to guess the output of this program before reading the continuation:

So the output is AB

Can anyone explain why for 1 argument function the priority is given to ellipsis, and for 2 argument to variadic template?

Aucun commentaire:

Enregistrer un commentaire