C 3プログラム猿C++教程ノート——関数テンプレート


関数テンプレート:関数のリロードを比較して、関数テンプレート、1つの関数だけで終わります
具体化:私たちが指定したタイプをtemplate<>void fun(job&j 1,job&j 2)だけ処理します.インスタンス化:指定したタイプの関数定義template void fun(job&j 1,job&j 2)を生成します.
#include 
using namespace std;

struct Node
{
	int a;
	double d;
};
//        ,               ,               
//    
template
void fun(T a )//        ,      ,      
{
	cout << a << endl;
}
//       
template<> void fun(Node no)
{
	cout << no.a << "  " << no.d << endl;
}
//       
template<> void fun(int a)
{
	cout << a << endl;
}
//    
void fun(int a)
{
	cout << a << endl;
}
//   
template void fun(double f);
int main()
{
	fun(12);
	fun(12.13);
	fun('a');
	fun("abc");
	//fun();
	system("pause");
	return 0;
}