Template vs function preference ( function having same name as template with same number of parameters)
So I stumbled upon this code (code attached),
Here if a call f() with int it gives 2 as output, but if i change the parameters to take a reference (even if I change both template and function to receive reference) rather than value, it gives 1 as output.
So basically my question is if template and a function are identical then which one would be called?(Normally the function is called but if i change the parameters to reference the template is called, so can someone clear this out and explain how this all works?).
Edit : ~ swim ~ So b/w T i and int i complier will choose int i, is that right?.
One more thing, is this compiler dependent or applies to every c++ complier?
Between T& i and const int& the compiler will choose T& as call matches better with T&.
const int& is a different type alltogether
Between T& and int& compiler will choose int& as call matches more closely to int parameter
Compiler always tries to choose most specialized form.