admin管理员组文章数量:1794759
Item 20: Facilitate the return value optimization.(More Effective C++)
The rules for C++ allow compilers to optimize temporary objects out of existence. As a result, if you call operator* in a context like this,
Rational a = 10; Rational b(1, 2); Rational c = a * b; // operator* is called hereyour compilers are allowed to eliminate both the temporary inside operator* and the temporary returned by operator*. They can construct the object defined by the return expression inside the memory allotted for the object c. If your compilers do this, the total cost of temporary objects as a result of your calling operator* is zero: no temporaries are created. Instead, you pay for only one constructor call — the one to create c. Furthermore, you can't do any better than this, because c is a named object, and named objects can't be eliminated
转载于:wwwblogs/zhtf2014/archive/2012/03/09/2387538.html
本文标签: facilitateItemEffectiveoptimizationreturn
版权声明:本文标题:Item 20:Facilitate the return value optimization.(More Effective C++) 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686986873a125736.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论