Bind non lvalue constant with rvalue reference

#include <iostream>
using namespace std;

int main() {
    int &&rfint = 10;
    int &l = rfint;
    std::cout << l << std::endl;
    std::cout << ++l << std::endl;
    std::cout << &l << std::endl;
    return 0;
}

Using the above construction, I can directly manipulate the value of prvalue 10using a non-const lvalue reference l. I can even go to the prvalue address. How it works? Does this have a long life span ?

+4
source share
1 answer

[dcl.init.ref] / 5:

"cv1 T1" "cv2 T2" :
...
(5.2.2.2). T1 , "cv1 T1" (8.5) . .

, int &&rfint = 10; , , 10.

, rfint, , , rfint .

+2

All Articles