标签:this end style div 3.3 his template class float
1.模板函数
// 定义 template <class T> Max(T &t1, T &t2) { return ((t1 > t2) ? t1 : t2); } //使用 Max(1, 2); Max(2.2, 3.3);
2.模板类
//定义 template <class T1, class T2> class myClass { private: T1 t1; T2 t2; public: myClass() {} myClass(T1 t1, T2 t2) {this->t1 = t1; this->t2 = t2;} void printMax() { cout << ((t1 > t2) ? t1 : t2) << endl; } }; // 使用 myClass<int, float> c1(1, 2.2); c1.printMax();
标签:this end style div 3.3 his template class float
原文地址:https://www.cnblogs.com/yangxinrui/p/9822331.html