PODs, non-PODs, rvalue and lvalues

前端 未结 3 2098
说谎
说谎 2020-12-25 13:21

Could anyone explain the details in terms of rvalues, lvalues, PODs, and non-PODs the reason why the first expression marked below is not ok while the secon

3条回答
  •  温柔的废话
    2020-12-25 14:09

    In my understanding both int() and A() should be rvalues, no?

    Correct, the epxression T() is always an rvalue for scalar and user-defined types T. As long as no const is involved, the expression T() is a modifiable rvalue, to be more precise.

    Assignment involving scalar types requires a modifiable lvalue on the left hand side of the assignment operator. Since int() isn't an lvalue, you can't assign to int().

    For user-defined types, assignment is a special member function, and member functions can also be called on rvalues (see §3.10 section 10). That's why A().operator=(a) is well formed.

提交回复
热议问题