So the reference collapsing rules are like:
+------+-----+--------+
| T | Use | Result |
|------|--------------|
| X& | T& | X& |
| X& | T&& | X& |
| X&& | T& | X& |
| X&& | T&& | X&& |
+------+-----+--------+.
I'm having a difficulty understanding the 3rd rule. It essentialy says that a reference to a rvalue collapses to a lvalue reference, does it not?
How could you pass a rvalue by reference? The following code is illegal:
int foo(int& i) {
std::cout << i << std:endl;
}
int main (int argc, char** argv) {
return foo(43); // Passing rvalue (i.e T&&)
}
I'm clearing missing something here :) Cheers
Aucun commentaire:
Enregistrer un commentaire