Puzzle 24A Specialized String Theory

 #include <iostream>
 
 template​<​typename​ T>
 void​ serialize(T&) { std::cout << ​"template​​\n​​"​; } ​// 1
 
 template​<>
 void​ serialize<>(​const​ std::string&) { std::cout << ​"specialization​​\n​​"​; } ​// 2
 
 void​ serialize(​const​ std::string&) { std::cout << ​"normal function​​\n​​"​; } ​// 3
 
 int​ main()
 {
  std::string hello_world{​"Hello, world!"​};
  serialize(hello_world);
  serialize(std::string{​"Good bye, world!"​});
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

The program displays the following output: ...

Get C++ Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.