7

I'm sorry I couldn't come with a better title.

What the last ampersand & means in the following code snippet:

A & A::operator=(A rhs) &
{
    swap(*this, rhs);
    return *this;
}

Depending on the answer I would like to know if:

  • it makes sense only for operator= or can also be applied to any function
  • it is a new C++11 feature or if it already exists in C++98/03

If you need more context, I found this syntax here: https://stackoverflow.com/a/12653520/951426

There is a small explanation but I don't understand.

Edit (formatting and short answer to my questions):

  • it's not specific to operator=
  • it is a new C++11 feature necessary due to the new rvalues
Community
  • 1
  • 1
Guillaume Papin
  • 1,370
  • 11
  • 16
  • 4
    http://stackoverflow.com/questions/8610571/what-is-rvalue-reference-for-this# – zch Apr 04 '13 at 13:09
  • Thanks, that answer my question(s). Sorry for the duplicate. – Guillaume Papin Apr 04 '13 at 15:07
  • 8
    I think you dont't have to feel sorry, as this duplicate is not obvious at all. Others looking for the meaning of "'&' at the end of member function declaration" will not easily find the linked question. – Oberon Apr 04 '13 at 19:38
  • 2
    Anybody mind explaining why this was reopened? – Xeo Apr 04 '13 at 19:40
  • @GuillaumePapin and thanks for getting the destructor fixed on that existing answer. This is how SO content improves by avoiding duplicates! – sehe Apr 05 '13 at 00:54

0 Answers0