In the following code, the main function uses normal function instead of Template function.
#include <iostream>
using namespace std;
template <class T>
void num(T t){cout<<"T : "<<t;}
void num(int a){cout<<"wT : "<<a;}
int main()
{
num(5);
return 0;
}
What is the possible reason behind this?
To call the template method in this case, you need to invoke the method explicitly with
num<int>(5)instead ofnum(5). Although the compiler can infer, non-generic method is preferred to a generic one. You can take a look at this behavior here http://ideone.com/ccDJP.