本文介绍了参考 - 它是如何有用的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用引用,但我不知道为什么它们存在而不是

来添加到语言中。它们实际上是否需要它们?

I know how to use references but i DO not get WHY they exist other than
to add to the language. Are they actually needed for anything?

推荐答案




因为他们基本上是伪装的指针,他们不是真的需要b $ b b b只需添加一些美感/逻辑结构......



Since they''re basically pointers in disguise, they''re not really
needed, they just add some "beauty"/logical structure...




因为它们基本上是伪装的指针,它们并不是真的需要它们,它们只是添加了一些美丽/逻辑结构...



Since they''re basically pointers in disguise, they''re not really
needed, they just add some "beauty"/logical structure...




如果没有它们,就不可能超载运营商。


-Mike



It''s not possible to overload operators without them.

-Mike




因为它们基本上是伪装的指针,它们并不是真的需要它们,它们只是添加了一些美丽/逻辑结构...



Since they''re basically pointers in disguise, they''re not really
needed, they just add some "beauty"/logical structure...



需要引用作为operator =的返回类型,因此x = y =

z按预期工作,等等。在其他几个地方,他们真的需要



其他地方,一般来说,它们很有用,因为你不能覆盖

指针上的运算符,所以使用引用将事物保持为

''对象''。当然,在大多数情况下,你可以取消引用,

但是,它会变得丑陋。


References are needed as a return type for operator =, so that x = y =
z works as expected, etc. There may be a few other places where they
are truly needed.

Everywhere else, in general, they are useful because you can''t override
operators on the pointers, so using references keeps things as
''objects''. Of course, in most of those cases, you could dereference,
but yeah, it would get ugly.


这篇关于参考 - 它是如何有用的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 05:07