模版的簡單使用

#include "max.h"

template <typename T>

inline T const& maxTwoObject(T const& a, T const& b){
 return a>b?a:b;
}

 

 

#include "max.h"
#include <iostream>
#include <string>
using namespace std;

int main(){

 int i = 42;
 cout<<maxTwoObject(7,i)<<endl;

 double f1 = 3.4;
 double f2 = -6.7;
 cout<<maxTwoObject(f1,f2)<<endl;

 string s1 = "mathematics";
 string s2 = "math";
 cout<<maxTwoObject(s1,s2)<<endl;

 return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章