本文介绍了通过引用比通过价值更贵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种情况,其中pass-by-reference比C ++中的pass-by-value更昂贵?
Is there a case where pass-by-reference is more expensive than pass-by-value in C++? If so, what would that case be?
推荐答案
希望传递基本类型(int,char,float,...)
Prefer passing primitive types (int, char, float, ...) and POD structs that are cheap to copy (Point, complex) by value.
这将比通过引用传递时所需的间接效率更高。
This will be more efficient than the indirection required when passing by reference.
请参阅。 p>
See Boost's Call Traits.
这篇关于通过引用比通过价值更贵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!