Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. int f() { return 2;}
  2. double f() { return 2.7;}
  3.  
  4. #include <cstdio>
  5.  
  6. template <typename typed> typed f() { return 2.7; }
  7.  
  8. int main(void) { return !printf("%d %f", f<int>(), f<double>()); }
  9.  
  10. #include <cstdio>
  11.  
  12. //template <typename typed> typed f() { return f<void>(); }
  13. //template <typename typed> typed f() { return f<void>(); return f<int>(); }
  14. template <typename typed> typed f();
  15.  
  16. template <> int f() { return 2; }
  17. template <> double f() { return 2.7; }
  18.  
  19. int main(void) { return !printf("%d %f", f<int>(), f<double>()); }
  20.  
  21. template<typename T> T f();
  22. template<> int f() { return 2; }
  23. template<> double f() { return 2.7; }
  24.  
  25. int x1 = f<int>();
  26. double y1 = f<double>();
  27.  
  28. struct F {
  29. F() {}
  30. template<typename T> operator T() { return f<T>(); }
  31. };
  32.  
  33. int x2 = F();
  34. double y2 = F();
  35.  
  36. auto a = F();
  37.  
  38. #include <iostream>
  39.  
  40. using namespace std;
  41.  
  42. namespace _double
  43. {
  44. double f()
  45. {
  46. return 2.6;
  47. }
  48. }
  49. namespace _int
  50. {
  51. int f()
  52. {
  53. return 2;
  54. }
  55. }
  56.  
  57. int main()
  58. {
  59. cout << _double::f() << " " << _int::f() << endl;
  60. cin.get();
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement