Answer the question
In order to leave comments, you need to log in
How does this recursion work?
Good afternoon everyone. I have this code:
template <typename T>
void foo(T value) {
return;
}
template<typename T, typename... Args>
void foo(T value, Args... arg)
{
std::cout << sizeof(value) << " | ";
foo(arg...);
}
int main()
{
MyClass a;//объект какого то класса
foo(89.8, a, 234.2,3,'a',0);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Because when instantiating the template foo(89.8, a, 234.2,3,'a',0) you get
foo(a, 234.2,3,'a',0)
foo(234.2,3,'a',0) )
foo(3,'a',0)
foo('a',0)
foo(0)
Each function prints its first parameter and calls itself with the parameter pack that cut off the first one.
The last call is to a function that doesn't print anything, so your last parameter isn't printed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question