模板 template 的类型转换

来源:互联网 发布:mac 打开隐藏文件 编辑:程序博客网 时间:2024/06/05 04:19

template<typename T>

T to(int n)

{

return (T)n;

}



double d = to<double>(3);

float  f = to<float>(2);


还可以这样用,挺有意思的

原创粉丝点击