美文网首页
Implicit typecast

Implicit typecast

作者: Sicuso | 来源:发表于2016-04-09 01:01 被阅读11次
        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

      本文链接:https://www.haomeiwen.com/subject/ahavlttx.html