Implicit typecast

        int i =2;
    double &r =i;
    r = 3;
    cout << i << endl;
    cout << r << endl;

will report

error: non-const lvalue reference to type 'double' cannot bind to a value of unrelated type 'int'

But

        int i =2;
    double &&r =i;
    r = 3;
    cout << i << endl;
    cout << r << endl;

just works fine.

The reason is that implicit typecast has created a anonymous(rvalue) variable.

你可能感兴趣的:(Implicit typecast)