fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<class T = int>
  5. class MyClass {
  6. public:
  7. void f() { cout << "D\n"; }
  8. };
  9.  
  10. template<>
  11. class MyClass<int> {
  12. public:
  13. void f() { cout << "S1\n"; }
  14. };
  15.  
  16. template<>
  17. class MyClass<double> {
  18. public:
  19. void f() { cout << "S2\n"; }
  20. };
  21.  
  22.  
  23. int main() {
  24. MyClass<double> a; // 1
  25. a.f(); //S2
  26.  
  27. MyClass<> b; // 2
  28. b.f(); //S1
  29.  
  30. MyClass<int> c; // 3
  31. c.f(); //S1
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
S2
S1
S1