fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5.  
  6. template <class T> //для lvalue
  7. T&& go(T& x )
  8. {
  9. return static_cast<T&&>(x);
  10. }
  11.  
  12. template <class T >
  13. T&& go(T&& x) //rvalue
  14. {
  15. return static_cast<T&&>(x);
  16. }
  17.  
  18. class Huston
  19. {
  20. int a;
  21. public:
  22. Huston(int& f) :a(f)
  23. {
  24.  
  25. }
  26. Huston(int&& b) :a(move(b))
  27. {
  28.  
  29. }
  30. };
  31. int func(int b ){ return b; }
  32. int main()
  33. {
  34.  
  35. int b = 3;
  36. Huston a(go(b));//move constructor is called
  37. Huston c(go(2));//move constructor is called
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 3336KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:36:18: error: call of overloaded ‘go(int&)’ is ambiguous
     Huston a(go(b));//move constructor is called
                  ^
prog.cpp:36:18: note: candidates are:
prog.cpp:7:5: note: T&& go(T&) [with T = int]
 T&& go(T& x )
     ^
prog.cpp:13:5: note: T&& go(T&&) [with T = int&]
 T&& go(T&& x)                  //rvalue
     ^
stdout
Standard output is empty