函数模板

Tmp为用户自定义的名字


template< typename Tmp>


适用于所有类型


#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
template<typename Tmp>
Tmp Add( Tmp a, Tmp b) {
    return a + b ;
}
int main() {
    double x = 5.8, y = 9.3;
    cout << Add(x, y) <<  endl;
    string a = "Hello ", b = "World!";
    cout << a + b << endl;
    return 0;
}
posted @ 2017-12-23 21:54  WenOI  阅读(103)  评论(0编辑  收藏  举报
水波背景