这两个功能有什么区别? (功能参考) [英] What is difference between these two function? (function reference)

查看:97
本文介绍了这两个功能有什么区别? (功能参考)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我看到的常见功能。

This is common function that I see.

std::string foo(){}





但不是这个



but not this

std::string &foo(){}





第二个是什么。

它们的作用有何不同?

我明白



What is the second one.
What the difference in what they do?
I understand that

std::string foo(int &a){}

通过引用传递。

第二个foo ...它是通过引用传递功能还是什么?



我尝试过:



我在quora的一个问题中遇到过这个函数。

仍然不明白。所以我在这里问。希望任何人都可以帮助

is passing by reference.
The second foo... it is pass function by reference or what?

What I have tried:

I came across this function on one of my question in quora.
Still didn't understand. So I ask here. Hope anybody can help

推荐答案

更好地将其读作
std::string&  foo()

该函数返回对字符串对象的引用,而不是字符串对象。

The function returns a reference to a string object instead of a string object.


这篇关于这两个功能有什么区别? (功能参考)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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