在C ++中,什么&在函数的返回类型之后的平均值? [英] In C++, what does & mean after a function's return type?

查看:130
本文介绍了在C ++中,什么&在函数的返回类型之后的平均值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这样的C ++函数中:

In a C++ function like this:

int& getNumber();

& 是什么意思?它不同于:

what does the & mean? Is it different from:

int getNumber();


推荐答案

是的, int& 版本返回对 int 的引用。 int 版本通过值返回 int

Yes, the int& version returns a reference to an int. The int version returns an int by value.

请参阅C ++常见问题中的参考部分

See the section on references in the C++ FAQ

这篇关于在C ++中,什么&在函数的返回类型之后的平均值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆