fork(2) download
  1. #include <iostream>
  2.  
  3. namespace My
  4. {
  5.  
  6. template <typename T>
  7. class MyClass {
  8. public:
  9. void dosome();
  10. void doother();
  11. };
  12.  
  13. template <typename T>
  14. void MyClass<T>::dosome() {}
  15. template <typename T>
  16. void MyClass<T>::doother() {}
  17.  
  18. template<> void MyClass<char>::dosome(); // Don't forget this
  19.  
  20. }
  21.  
  22. template<>
  23. void My::MyClass<char>::dosome() {
  24. std::cout << "specialization" << std::endl;
  25. }
  26.  
  27.  
  28. int main() {
  29. My::MyClass<int> a;
  30. My::MyClass<char> b;
  31. a.dosome(); // This must call the generic template definition
  32. b.dosome(); // This must call the specialization
  33. a.doother(); // This must call the generic template definition
  34. b.doother();
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
specialization