函数返回值与通过引用传递的修改值 [英] Function returning value vs modifying value passed by reference

查看:138
本文介绍了函数返回值与通过引用传递的修改值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下,最好返回一个对象,而不是仅仅修改通过引用传递给该函数的对象?我如何知道应该选择哪一个?

In what situations it is preferred to return an object instead of just modifying an object passed to that function by reference? How do I know which one should I pick?

实际上,问题是如果有没有能力返回一个对象

Actually, the question is if there are things I wouldn't be able to do without the ability to return an object from function, but instead only modifying objects passed by reference.

推荐答案

 TYPE function () ;

 void function (TYPE &value) ;

是前者可用于表达式。

a = 10 * function () ;

if(function())
{
}

if (function ()) { }

这是主要的设计考虑。

除此之外,我必须得到意见。我将坚持客观的差异。

Beyond that, I would have to get into opinion. I am going to stick to the objective difference.

这篇关于函数返回值与通过引用传递的修改值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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