Code in Function3.h:
#ifndef Function3_h#defineFunction3_h#include<string>#include<cstring>#include<iostream>Template<typename t>T Mymax (ConstT P1,ConstT p2) {Std::cout<<"Template default Func"<<Std::endl; returnP1 < P2?P2:p1;}//The compiler would use ' template int func ' as the specialization for ' template default func 'Template <>intMymax (intInt1,intInt2) {Std::cout<<"Template int func"<<Std::endl; returnInt1 < Int2?int2:int1;}//The compiler would use ' int func ' as the instantiation for ' template default func '//It has-is put after ' template int func 'intMymax (intInt1,intInt2) {Std::cout<<"int func"<<Std::endl; returnInt1 < Int2?int2:int1;}#endif //Function3_h
Test Code main.cpp:
#include <iostream>#include"function3.h"using namespacestd;intMain () {cout<< Mymax (21.0,31.0) <<Endl; cout<< Mymax ( +, to) <<Endl; cout<< mymax<int> ( +, to) <<Endl; return 0;}
Results:
Function template Example (iii) Special and overloaded template functions