Having Fun With C++ [Quiz Series- Part 1]

Table of Content

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!

The 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 );

}

Hint:

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.

Know the answer?

Send it to us at marketing@www.incredibuild.cn. The winners will be announced on our social pages.

 

speed up c++

 

Table of Content

缩短你的构建

Incredibuild 使您的团队能够提高工作效率并专注于创新。
分享

相关博客文章

CI/CD
CRA 如何防止近期供应链攻击
[4 11 月 2025]
Made CI 85% Faster
C++, CI
我们如何让 CI 快 85% —— 内部先行实践实录
[30 10 月 2025]
Written words: Agentic AI
C++, DevOps
Agentic AI 如何改变软件开发
[23 10 月 2025]
[wpml_language_selector_widget]