cppquiz icon indicating copy to clipboard operation
cppquiz copied to clipboard

Improvements to the answer of question №124

Open AliAshkaniNia opened this issue 1 year ago • 0 comments

Hi, I think there is a small typo in the answer to question №124. At the end of second paragraph, it is written: ... so the default arguments of C (i.e. T = B) are applied and C<B>::f() is called inside g().

I think you meant X<B>::f() instead of C<B>::f(), as C is the argument and X is the actual struct containg f(). I propose the following revision of the second paragraph for better accuracy:

In this code snippet, the template template-parameter is C, and the scope of C is the function template g(). Therefore, the default template argument for C (which is T = B) is applied. This means that when g<X>() is called, it is equivalent to calling g<X<B>>(), which in turn calls X<B>::f(). As X<B>::f() is specialized to print 2, the output of the program is 2.

AliAshkaniNia avatar Apr 09 '24 14:04 AliAshkaniNia