//导入C的头文件
extern "C" {
#include <stdio.h>
}
using namespace std;
//模板方法
template <class T>
T GetMax(T a, T b){
return a > b ? a : b;
}
//模板类
template <class T>
class MyPair {
T values [2];
public :
MyPair (T f, T s){
values[0] = f;
values[1] = s;
}
T getValue(int i){
return values[i];
}
};
int main(void){
const char* msg = "gaojie";
printf("hellword=>%s\n", msg);
int a = 10, b =900 ;
cout << "GetMax:" << GetMax(a, b) << endl;
// int 类型
MyPair<int> mp(a, b);
cout << "values[0]=" << mp.getValue(0) << ", values[1]=" << mp.getValue(1) << endl;
//const char *
MyPair<const char*> mps("name:", msg);
cout << "v[0]=" << mps.getValue(0) << ", v[1]="<<mps.getValue(1) << endl;
return 0;
}
转载于:https://my.oschina.net/u/139611/blog/180793