简体   繁体   中英

Why doesn't NRVO work without copy constructor

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...".

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM