As we know when we do function overloading in template function with ordinary function, If the compiler get the exact match with ordinary fun()
it will call ordinary fun()
and ignore the template fun()
.
But in the below C++ code when I run the code it call the template function not ordinary function.
Why?
Code
#include<iostream>
using namespace std;
template<class T1, class T2>
void fun(T1 x, T2 y){
cout << "TEMPLATE FUNCTION : " << x << " | " << y << endl;
}
void fun(int a, float b){
cout << "ORDINARY FUNCTION : " << a << " | " << b << endl;
}
int main(){
fun(3, 4.7);
return 0;
}
Output
TEMPLATE FUNCTION : 3 | 4.7