Why doesn't NRVO work without copy constructor

时间秒杀一切 提交于 2019-12-13 06:59:34

问题


I'm reading the book Inside C++ Object Model and I got things below:

As I know, NRVO won't call the copy constructor of the class that a function returns.So I don't understand why "This first verison of the program does not apply NRV optimization because of the absence of a copy constructor...".


回答1:


The idea is that the code should work both for compilers that perform the optimization and for those that don't. If the object is copied, obviously the copy constructor must be defined and accessible. So that's the requirement, even for those compilers that might not always use it.

Like said in the comments, C++17 will make the optimizations mandatory and can then relax the requirements.



来源:https://stackoverflow.com/questions/42645939/why-doesnt-nrvo-work-without-copy-constructor

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