【发布时间】:2011-05-06 00:04:29
【问题描述】:
可能的重复:
How to pass objects to functions in C++?
is there any specific case where pass-by-value is preferred over pass-by-const-reference in C++?
我有一个这样实现的类的成员:
void aaa(int a, float b, short c)
{
bbb(a, b);
}
void bbb(int a, float b)
{}
如果 a、b 和 c 的值作为常量存储在我的类中,那么使用如下所示或如上所示的函数会更好/更明智吗?
void aaa(int& a, float& b, short& c)
void bbb(int& a, float& b)
在这种情况下,使用引用是否会给速度带来任何好处或优势?这里引用的任何缺点/开销?
【问题讨论】:
-
好吧,那些
*是关于什么的?! -
我想你需要编辑格式 int**&** 没有意义:-)
-
星号是由 StackOverflow 添加的。该网站应该将星号之间的字母转换为粗体。将删除它,因为它没有转换。
标签: c++ performance reference