c_-_c_templates:template_specialization
C - C++ Templates - Template specialization
#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; }
c_-_c_templates/template_specialization.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1