fork download
  1. #include <iostream>
  2.  
  3.  
  4. namespace namespace_scope {
  5.  
  6. struct type {
  7.  
  8. template<typename T>
  9. T method();
  10.  
  11. // template<>
  12. // int method<int>() {}
  13. //
  14. // template<>
  15. // float method() {}
  16. };
  17.  
  18. template<>
  19. int type::method<int>() {
  20. return 1;
  21. }
  22.  
  23. template<>
  24. float type::method() {
  25. return .5f;
  26. }
  27.  
  28. }
  29.  
  30.  
  31. int main() {
  32. namespace_scope::type object;
  33. std::cout << object.method<int>() << std::endl;
  34. std::cout << object.method<float>() << std::endl;
  35. }
  36.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
1
0.5