Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no reason why that reference would be wrong or bad. If what you want is a local short-cut name ("alias"), references are <em>the</em> way to go. If you copy the float into a new variable, then you will get a new object and as you pointed out, of course you will also get a new address: Not at all what you would have wanted. So take a reference for that:</p> <pre><code>float &amp;x = some.buried.variable.elsewhere; </code></pre> <p>Which will behave as the original variable in expressions. </p> <p>However, as with everything, hard-coded rules won't do it. It depends on the specific situation. If you don't care about the <em>object</em>, but rather about the object's <em>value</em>, then create a copy. It's better to use the float directly than have that possible indirection through a reference when all you are interested in is to get easy access to the <em>value</em> of something. </p> <p>What is bad is to use a reference when storing the result of a computation - because what is clearly of interest is the value only. You couldn't have any interest in a temporary float identity anyway, because it doesn't exist in the first place: A temporary float is not an object. It isn't even required to have any address (which can happen if the compiler keeps the float in a register):</p> <pre><code>float const &amp;x = 3.0; // non-sense. don't use reference here </code></pre> <p>Same with the result of a function call of course</p> <pre><code>float const &amp;x = get_some_float(); // non-sense too. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload