Consider the following code:
#include <iostream> template<typename T> void f(T t) { (void)t; std::cout << "templated f(T)\n"; } template<typename T> void entry(T t) { f(t); } void f(double d) { (void)d; std::cout << "normal f(double)\n"; } int main() { double d = 0.0; entry(d); return 0; }
Output:
templated f (T)
I find this amazing because I thought that a simple function would be chosen by any template version. Why is this happening?
Another thing that I noticed during the game is that: if I put the normal function void f(double) before using templated void entry(T) , the code will call a normal function, basically outputting:
normal f (double)
So my other question is: why the question of order in this particular example?
source share