dimanche 1 janvier 2017

Why passing rvalue reference (X&&) is AS IF passing lvalue reference (X&)?

While I was studying rvalue reference, I found a strange answer from stackoverflow.
Here is a modified code :-

void foo(X& x)  {   }          //#A
void foo(X&& x) { foo(x);   }  //#B

Why doesn't this lead to stack overflow exception?
Why foo#B call foo#A, but not foo#B?

More specifically, which C++ rule enforces this behavior?

Aucun commentaire:

Enregistrer un commentaire