您的位置:首页 > 其它

函数模板

2014-01-16 18:57 162 查看
///////////////////////////function.cpp//////////////////////////

template < typename T >

string type(T t)

{

return Type<T>::name();

}

int main()

{

cout << type(123) << endl; // 对于函数模板,可以根据实参推测形参类型名

cout << type(45.6) << endl;

int a=10;

char b='k';

cout << type(a/1.0) << endl; // double

cout << type(a<b) << endl; // bool

cout << type<&a> << endl; // int pointer

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: