+ 4

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?). https://code.sololearn.com/c8qaz0o0AcdP/?ref=app 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?

25th Aug 2019, 10:06 AM
bufftowel
bufftowel - avatar
0 Answers