
Joseph Sibony
reading time:
While C++ is always fun (except for C++ build times, of course), there are moments where we really get to have a blast. For me, the following C++ quiz is one of these moments. I’m not sure what did it for me. Was it the thrill of solving a challenge, or just the chance to play around with the language like a kid.
I hope you’ll have as much fun as I had.
Thanks to Anders Schau Knatten from CppQuiz for creating this quiz!
#include <iostream>
template<class T>
void f(T) { std::cout << 1; }
template<>
void f<>(int*) { std::cout << 2; }
template<class T>
void f(T*) { std::cout << 3; }
int main() {
int *p = nullptr;
f( p );
}
Before I spoil everything and reveal the answer, here’s a nice hint for you:
A declaration of a function template being explicitly specialized shall precede the declaration of the explicit specialization. During overload resolution, only the base function templates are considered, not specializations.
Send it to us at [email protected]. The winners will be announced on our social pages.

Shorten your builds
Incredibuild empowers your teams to be productive and focus on innovating.
Incredibuild empowers your teams to be productive and focus on innovating.
| Cookie | Duration | Description |
|---|---|---|
| cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
| cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
| cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
| cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
| cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
| viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |