上代码:
#include <iostream>
#include<string>
template<typename T>
void printf (T const&);
int main()
{
printf<std::string>("日你妹,好用了!");
system("pause");
return 0;
}
template<typename T>
void printf (T const& content)
{
std::cout<< content << std::endl;
}
函数模板声明时也不能少了template<typename T>这个固定格式。
还有一点,函数声明的时候,不需要带上形参,写上参数类型就ok.