//function Template Overloading#include <iostream>using namespacestd;/*function templates are strictly type-matched, and template types do not provide implicit type conversions ordinary functions are capable of automatic type conversions*//* function template overloading four rules 1 function templates can be overloaded like normal functions 2 C + + compiler takes precedence over normal function 3 If the function template can produce a better match, then select template 4 can pass the syntax of the empty template argument list to qualify the compiler to match only through templates */Template<typename t>voidTest1 (t A, T b) {cout<<"executed the template function Test1 ()"<<Endl;}voidTest2 (intAintb) {cout<<"executed the Test2 ()"<<Endl;}voidTest1 (intAintb) {cout<<"performed a common function Test1 ()"<<Endl;}voidTEST3 (intAintb) {cout<<"performed a common function Test3 ()"<<Endl;}voidProtecta () {intA =1; intb =2; Charc ='3'; //Test1 (A, c); Error error C2782: "Void Test1 (T,t)": template parameter "T" ambiguous /*because A is an int, c is a char type and the function template requires that both parameters are T-type, which means that the type of the two arguments must be the same, but the int and char types are inconsistent so the error*/Test2 (A, c);//for normal functions, implicit type conversions are possible, so no problem}voidPROTECTB () {intA=1, b=2; Charc ='3', d='4'; Test1 (A, b);//call the normal function hereTest1<> (A, b);//call the template function here--rule 4Test1 (c, D);//call the template function here--rule 3---Assume that no template function will still call the normal functionTest3 (c, D);}voidMain () {PROTECTB (); System ("Pause");}
C + + function template Two (function template overloading)