fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class test
  5. {
  6. public:
  7. int &foo() &
  8. {
  9. cout << "lvalue" << endl;
  10. return m_i;
  11. }
  12. int foo() &&
  13. {
  14. cout << "rvalue" << endl;
  15. return m_i;
  16. }
  17.  
  18. private:
  19. int m_i;
  20. };
  21.  
  22. int main() {
  23. // your code goes here
  24. test rawr;
  25. rawr.foo() = 1;
  26. cout << rawr.foo();
  27. return 0;
  28. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
lvalue
lvalue
1