Wednesday, October 26, 2016

Overloading Function Template :)

Tags

When we overload a function template by defining function with same signature but with any particular type then if called function is an exact match of the normal function then it is called.
else the template function is called.
Following Program Illustrates The Concept:

#include<iostream>
using namespace std;
template<class T>
void display(T x)
{
cout<<"\nTemplate Function\n";
cout<<"Value Passed: "<<x;
}
void display(int x)
{
cout<<"\nNormal Function\n";
cout<<"Value Passed: "<<x;
}
main()
{
display(5);
display('N');
}

Output: