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

前端 未结 11 1813
长情又很酷
长情又很酷 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:26

    The evil workaround involves the 'mutable' keyword. Actually being evil is left as an exercise for the reader. Or see here: http://www.ddj.com/cpp/184403758

提交回复
热议问题