On how to recognize Rvalue or Lvalue reference and if-it-has-a-name rule

前端 未结 3 1037
一生所求
一生所求 2020-11-30 05:07

I was reading Thomas Becker\'s article on rvalue reference and their use. In there he defines what he calls if-it-has-a-name rule:

Things tha

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 05:47

    While the rule covers a majority of case, I can't agree with it in general:

    The dereferencing of an anonymous pointer does not have a name, yet it is an lvalue:

    foo(*new X);  // Not allowed if foo expects an rvalue reference (example of the article)
    

    Based on the standard, and taking into account the special cases of temporary objects being rvalues, I'd suggest to update the second sentence of the rule :

    " ... The criterion is: if it designates a function or an object which is not of temporary nature, then it's an lvalue. ... ".

提交回复
热议问题