fork download
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. template <class T1, class T2 = void>
  7. class A
  8. {
  9. public:
  10.  
  11. void f()
  12. {
  13. t1 = t2.get();
  14. }
  15.  
  16. T1 result() {cout << "2\n"; return t1;}
  17. private:
  18. T1 t1;
  19. T2 t2;
  20. };
  21.  
  22. template<class T1>
  23. class A<T1, void>
  24. {
  25. public:
  26.  
  27. void f() {/*do nothing*/}
  28. T1 result() { cout << "1\n"; return t1;}
  29.  
  30. T1 t1;
  31. };
  32.  
  33. int main(int argc, char * argv[])
  34. {
  35. A<int> a;
  36. A<int,int> b;
  37. a.result();
  38. b.result();
  39. }
  40.  
Success #stdin #stdout 0.01s 5392KB
stdin
Standard input is empty
stdout
1
2