Are all temporaries rvalues in C++?

前端 未结 7 925
隐瞒了意图╮
隐瞒了意图╮ 2020-12-05 04:56

I have been coding in C++ for past few years. But there is one question that I have not been able to figure out. I want to ask, are all temporaries in C++, rvalues?

7条回答
  •  难免孤独
    2020-12-05 05:11

    If no, can anyone provide me an example where temporary produced in the code is an lvalue?

    The following code binds a constant reference to a temporary object of type const float created by the compiler:

    int i;
    const float &cfr = i;
    

    The behaviour is "as if":

    int i;
    const float __tmp_cfr = i; // introduced by the compiler
    const float &cfr = __tmp_cfr;
    

提交回复
热议问题