Since a string literal is considered an lvalue, why must the binding lvalue reference be const?

前端 未结 3 658
灰色年华
灰色年华 2021-02-19 05:42

I know there are topics that are similar to this one already (such as this).

The example given in this topic was this:

std::string & rs1 = std::strin         


        
3条回答
  •  有刺的猬
    2021-02-19 06:35

    The string literal may be an lvalue, but it's not a string object. There's a temporary string being created which is an rvalue.

提交回复
热议问题