A Specialized String Theory

Test your C++ programming skills by solving the given puzzle about template specialization and overload resolution.

Puzzle code

Carefully read the code given below:

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

Your task: Guess the output

Try to guess the output of the above code. Attempt the following test to assess your understanding.

The possible console output lines are given below on the right side column. Place them in the correct sequence.

Drag and drop the cards in the blank spaces.


Let’s discuss this code and output together in the next lesson.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.