return by value assigned to const reference

前端 未结 2 800
既然无缘
既然无缘 2020-12-09 04:43

I was fixing another bug in some code and came across some code that I would have thought was a bug; however, this code compiles under gcc 4.4, 4.5, and 4.6 and appears to f

2条回答
  •  死守一世寂寞
    2020-12-09 05:03

    Yes, this is legal C++. Forming a reference-to-const to a temporary extends the lifetime of the temporary to the lifetime of the reference.

提交回复
热议问题