类模板(函数模板)

来源:互联网 发布:衬衣品牌 知乎 编辑:程序博客网 时间:2024/03/29 18:58
#include <iostream>using namespace std;template<typename T>T abs(T x) {return x < 0?-x:x;}int main() {int n = -5;double d = -5.5;cout<<abs(n)<<endl;cout<<abs(d)<<endl;return 0;}

0 0
原创粉丝点击