Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5.   public:
  6.  
  7.   void print() &
  8.   {
  9.     std::cout << "lvalue!" << "\n";
  10.   }
  11.  
  12.   void print() const&
  13.   {
  14.     std::cout << "const lvalue!" << "\n";
  15.   }
  16.  
  17.   void print() &&
  18.   {
  19.     std::cout << "rvalue!" << "\n";
  20.   }
  21. };
  22.  
  23. int main()
  24. {
  25.   A lvalue {};
  26.   lvalue.print();
  27.   A().print();
  28.  
  29.   const A& constLvalue = lvalue;
  30.  
  31.   constLvalue.print();
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement