函數模板

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;
}
發佈了50 篇原創文章 · 獲贊 9 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章