fork download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. void WhoAmI() &&
  6. {
  7. std::cout << "I am rvalue reference\n";
  8. }
  9.  
  10. void WhoAmI() const &&
  11. {
  12. std::cout << "I am const rvalue reference\n";
  13. }
  14.  
  15. };
  16.  
  17.  
  18. A operator+(A a1, A a2)
  19. {
  20. return {};
  21. }
  22.  
  23. int main()
  24. {
  25. A a;
  26. // a.WhoAmI(); // error
  27.  
  28. A& ra = a;
  29. ra.WhoAmI(); // error
  30.  
  31. (a + a).WhoAmI(); // ok
  32.  
  33. return 0;
  34. }
  35.  
Compilation error #stdin compilation error #stdout 0s 15232KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29:13: error: passing ‘A’ as ‘this’ argument discards qualifiers [-fpermissive]
   ra.WhoAmI(); // error
             ^
prog.cpp:5:8: note:   in call to ‘void A::WhoAmI() &&’
   void WhoAmI() &&
        ^~~~~~
stdout
Standard output is empty