fork download
  1. #include <iostream>
  2.  
  3. struct Outer
  4. {
  5. template<typename T>
  6. void go()
  7. {
  8. std::cout << Test<T>::f() << std::endl;
  9. }
  10. private:
  11. template<typename T>
  12. struct Test
  13. {
  14. static int f();
  15. };
  16. };
  17.  
  18. template<> int Outer::Test<int>::f();
  19. template<> int Outer::Test<double>::f();
  20. extern template struct Outer::Test<int>;
  21. extern template struct Outer::Test<double>;
  22.  
  23. int main()
  24. {
  25. Outer o;
  26. o.go<int>();
  27. o.go<double>();
  28. }
  29.  
  30. template<>
  31. int Outer::Test<int>::f()
  32. {
  33. return 1;
  34. }
  35. template<>
  36. int Outer::Test<double>::f()
  37. {
  38. return 2;
  39. }
  40.  
  41.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
1
2