c++类模板

来源:互联网 发布:淘宝蜂蜜店铺推荐 编辑:程序博客网 时间:2024/06/08 06:05
#include <iostream>using namespace std;template <class T>class mypair {    T a, b;  public:    mypair (T first, T second)      {a=first; b=second;}    T getmax ();};template <class T>T mypair<T>::getmax (){  T retval;  retval = a>b? a : b;  return retval;}int main () {    mypair <int> myobject (100,35);    cout << myobject.getmax() << endl;    return 0;    }