A Specialized String Theory
Test your C++ programming skills by solving the given puzzle about template specialization and overload resolution.
We'll cover the following
Puzzle code
Carefully read the code given below:
#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.
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.