從一些幻燈片模板左右專業化:模板功能專業化與超載
#include <iostream>
using namespace std;
template<class X>
X& min(X& a, X& b)
{
return a > b ? b : a;
}
int& min(int& a, int & b)
{
// rewrite of the function in the case of int:
cout << "int explicit function\n";
return a > b ? b : a;
}
/*
new syntax – the more appropriate way:
template<>
int& min<int>(int& a, int& b)
{
cout << "int explicit function\n";
return a > b ? b : a;
}
*/
爲什麼第二種方式更「合適」?
相關閱讀:[爲什麼不專業化功能模板?](http://www.gotw.ca/publications/mill17.htm) – juanchopanza
這些幻燈片是否在線提供? –
@Vaughn在Dropbox文件夾中... – nodwj