c – 通过参考比通过价值更贵

前端之家收集整理的这篇文章主要介绍了c – 通过参考比通过价值更贵前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有一种情况,通过引用比C中的pass-by-value更昂贵?如果是这样,那是什么情况呢?

解决方法

喜欢通过值复制(Point,complex)的原始类型(int,char,float,…)和POD结构.

这将比通过引用时所需的间接更有效.

Boost’s Call Traits.

The template class call_traits<T> encapsulates the “best” method to pass a parameter of some type T to or from a function,and consists of a collection of typedefs defined as in the table below. The purpose of call_traits is to ensure that problems like “references to references” never occur,and that parameters are passed in the most efficient manner possible.

原文链接:https://www.f2er.com/c/115833.html

猜你在找的C&C++相关文章