class templates : template class « template « C++ Tutorial






#include <iostream.h>

template <class T>
class MyClass {
    T value1, value2;
  public:
    MyClass (T first, T second){
        value1=first; 
        value2=second;
    }
    T getmax ()
    {
      T retval;
      retval = value1>value2 ? value1 : value2;
      return retval;
    }
    
};

int main () {
  MyClass <int> myobject (100, 75);
  
  cout << myobject.getmax();
  
  return 0;
}
100"








13.1.template class
13.1.1.class templates
13.1.2.template class Demo
13.1.3.Generic Vector
13.1.4.template class 2
13.1.5.template holder class
13.1.6.template counter
13.1.7.Calculate with SArray