Puzzle 2String Theory

 #include <iostream>
 #include <string>
 
 void​ ​serialize​(​const​ ​void​*) { std::cout << ​"const void*"​; }
 
 void​ ​serialize​(​const​ std::string&) { std::cout << ​"const string&"​; }
 
 int​ ​main​()
 {
  serialize(​"hello world"​);
 }

Guess the Output

images/aside-icons/important.png

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

images/hline.png

The program displays the following output:

 const void*
images/hline.png

Discussion

Why does passing ...

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.