prolonging the lifetime of temporaries

前端 未结 4 509
太阳男子
太阳男子 2020-12-01 11:26

What is the design rationale behind allowing this

const Foo& a = function_returning_Foo_by_value();

but not this

Foo&am         


        
4条回答
  •  我在风中等你
    2020-12-01 11:49

    I have understood the rationale as follows: a temporary is expected to be destroyed when it goes out of scope. If you promise not to modify it I will let you prolong its lifetime.

提交回复
热议问题