admin管理员组文章数量:1130349
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 here
your 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
转载于:https://wwwblogs/zhtf2014/archive/2012/03/09/2387538.html
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 here
your 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
转载于:https://wwwblogs/zhtf2014/archive/2012/03/09/2387538.html
本文标签: facilitateitemEffectiveoptimizationreturn
版权声明:本文标题:Item 20:Facilitate the return value optimization.(More Effective C++) 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/jiaocheng/1754361063a2677952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论