Template specialization : Template specialization « 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 module () {return 0;}
};

template <>
class MyClass <int> {
    int value1, value2;
  public:
    MyClass (int first, int second){
        value1 = first; 
        value2 = second;
    }
    int module (){
        return value1value2;
    }
};

int main () {
  MyClass <int> myints (100,75);
  MyClass <float> myfloats (100.0,75.0);

  cout << myints.module() << '\n';
  cout << myfloats.module() << '\n';

  return 0;
}
25
0








13.6.Template specialization
13.6.1.Template specialization
13.6.2.Primary template to compute 3 to the Nth and full specialization to end the recursion
13.6.3.Partial specialization as end criteria