fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <class T>
  6. class MyClass {
  7. public:
  8. void func1(){
  9. cout<<"default: func1"<<endl;
  10. }
  11. void func2(){
  12. cout<<"default: func2"<<endl;
  13. }
  14. private:
  15. T haha;
  16. };
  17.  
  18. template <>
  19. void MyClass<double>::func1() {
  20. cout<<"special: func1"<<endl;
  21. }
  22.  
  23. int main()
  24. {
  25. MyClass<int> intclass;
  26. intclass.func1();
  27. intclass.func2();
  28.  
  29. MyClass<double> doubleclass;
  30. doubleclass.func1();
  31. doubleclass.func2(); // error 'class MyClass<double>' has no member named 'func2'
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
default: func1
default: func2
special: func1
default: func2