函數模板也能夠不一樣實參形參類型來實例化:ios
#include <iostream> #include <string> using namespace std; template <typename T> void print() { if (sizeof(T) == sizeof(char)) cout << "the function is speciallize as char" << endl; else if (sizeof(T) == sizeof(int)) cout << "the function is speciallize as int" << endl; } int main(void) { print<int>();//經過和類模板類似的形式實例化 print<char>(); return 0; }