How come a non-const reference cannot bind to a temporary object?

前端 未结 11 1809
长情又很酷
长情又很酷 2020-11-21 05:19

Why is it not allowed to get non-const reference to a temporary object, which function getx() returns? Clearly, this is prohibited by C++ Standard but I am in

11条回答
  •  一向
    一向 (楼主)
    2020-11-21 05:37

    Why would you ever want X& x = getx();? Just use X x = getx(); and rely on RVO.

提交回复
热议问题