函数返回值与通过引用传递的修改值

函数返回值与通过引用传递的修改值

问题描述:

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

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.