1

Good day!

May I ask the use of the ampersand(s) after a C++ function prototype as in the following struct get members taken from cppreference.com's std::forward page:

struct Arg
{
    int i = 1;
    int  get() && { return i; } // call to this overload is rvalue
    int& get() &  { return i; } // call to this overload is lvalue
};

? I understand the ampersands after the function return type but it's the first time I encounter ampersands after the function prototype.

  • This might help: https://stackoverflow.com/questions/8610571/what-is-rvalue-reference-for-this . Basically, the signature `int get() &&` is called when the object in question (that is, `*this`) is an rvalue. Mostly in order to move data. – Aziuth Aug 24 '21 at 09:50
  • Thank you @Aziuth! I now get this together with the answer above. – user2193946 Aug 25 '21 at 13:53

0 Answers0