knatten / cppquiz

Source for the http://cppquiz.org website (not the questions)
GNU General Public License v3.0
101 stars 14 forks source link

Improvements to the answer of question №124 #332

Closed AliAshkaniNia closed 6 months ago

AliAshkaniNia commented 7 months ago

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.

knatten commented 6 months ago

I like your suggestion! Have updated the explanation now: https://cppquiz.org/quiz/question/124?preview_key=wajefiwaje

AliAshkaniNia commented 6 months ago

That's great to hear! Happy to help.