Why is the output of this code :
#include <iostream>
template<typename T> void f(T param)
{
std::cout << "General" << std::endl ;
}
template<> void f(int& param)
{
std::cout << "int&" << std::endl ;
}
int main()
{
float x ; f (x) ;
int y ; f (y) ;
int& z = y ; f (z) ;
}
is
General
General
General
The third one is surprizing because the function was specialized exactly for int&
Edit : I know that overloading might be a proper solution. I just want to learn the logic behind it.
See Question&Answers more detail:os