函数模板也能够不一样实参形参类型来实例化: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; }