1. 函数模板 及 类模板 定义实现使用
Developer: ubantu_g++
//how to define a template function------------------------------------
cout<<"template function"<<endl\
//how to overload a template function------------------------------------
void print(T1 const& a, T2 const& b)
cout<<"multi-args and overload function"<<endl\
//how to define a template class------------------------------------
T content;
obj(T const& arg);
void print(void);
content = arg;
cout<<"template obj"<<endl\
//how to define a specialization class from a exist template class------------------------------------------
string content;
obj(const string & str);
void print(void);
obj<string>::obj(const string& str):content(str){}
cout<<"specialization template"<<endl\
//mult_args template calss------------------------------------------
T1 cont0;
T2 cont1;
obj_(const T1&, const T2&);
void print(void);
obj_<T1,T2>::obj_(const T1& a, const T2& b):cont0(a),cont1(b){}
cout<<"mult_args template calss"<<endl\
//partial specialization template class------------------------------------------
T cont0;
string cont1;
obj_(const T&, const string&);
void print(void);
obj_<T, string>::obj_(const T & a, const string & b):cont0(a),cont1(b){}
cout<<"partial specialization template class"<<endl\
int a = 100;
double b =1.111;
string str ("this is string");
//test template function
//test multi-types in template and overload it
//test template class
//test mulit-types class
obj_<string, int>object_m(str, a);
//test specialization template class
//test partial specialization template class
obj_<int ,string>object_(a,str);
//test instantial delay
//template obj<double>;显式实例化声名 无法通过编译
return 0;