rules with temporary objects and args by reference

老子叫甜甜 提交于 2019-12-06 11:24:54

There is a formal rule - the C++ Standard (section 13.3.3.1.4 if you are interested) states that a temporary can only be bound to a const reference - if you try to use a non-const reference the compiler must flag this as an error.

Herb Sutter does a fine job explaining it here: http://www.gotw.ca/gotw/081.htm

x() must either take a const reference to a temporary A, or x() must take an A by-value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!