fork download
  1. #include <iostream>
  2.  
  3. void foo( int*&& ) { std::cout << "foo( int*&& )\n" ; }
  4. void foo( int&& ) { std::cout << "foo( int&& )\n" ; }
  5.  
  6. void bar( int* const& ) { std::cout << "foo( int* const& )\n" ; }
  7. void bar( const int& ) { std::cout << "bar( const int& )\n" ; }
  8.  
  9. void baz( int*& ) { std::cout << "foo( int*& )\n" ; }
  10. void foo( int& ) { std::cout << "foo( int& )\n" ; }
  11.  
  12. void foobar( int* ) { std::cout << "foobar( int* )\n" ; }
  13. void foobar( int ) { std::cout << "foobar( int )\n" ; }
  14.  
  15. int main()
  16. {
  17. int a [] = {10,10,10,10,10,11,10,11};
  18. short s = 23 ;
  19.  
  20. foo(a); // fine a => rvalue of type int*; passed by reference to rvalue
  21. foo(s); // fine s => rvalue of type int; passed by reference to rvalue
  22.  
  23. bar(a) ; // fine a => rvalue of type int*; passed by reference to const
  24. bar(s) ; // fine s => rvalue of type int; passed by reference to const
  25.  
  26. // baz(a) ; // *** error, can't pass rvalue as reference to non-const lvalue
  27. //baz(s) ; // *** error, can't pass rvalue as reference to non-const lvalue
  28.  
  29. foobar(a) ; // fine a => rvalue of type int*; passed by value (pass a copy of the rvalue)
  30. foobar(s) ; // fine s => rvalue of type int; passed by value (pass a copy of the rvalue)
  31. }
  32.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
foo( int*&&  )
foo( int&&  )
foo( int* const&  )
bar( const int&  )
foobar( int* )
foobar( int  )