Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In C++, a "reference" denoted by <code>&amp;</code> implies that the caller of your method is obligated to provide you with an object instance. There is no (NORMAL) way to call your method without an object. You are free to assume that you if your function is called, the aAdjustement will be set to something.</p> <p>However, there are two gothas here:</p> <p>(1) It will be set to something, but will that 'something' be meaningful? Is a Adjustement structure completely zeroed-out a valid value for your function? If not - then you may test that instead test nulliness. If any structure value combinations are invalid - use this as the discriminator. If all possible values are valid - then there's nothing to be checked.</p> <p>(2) If you know the dark ways (tm), you actually CAN PASS a null-reference to this function. So your code is not "safe from nulls" just because "you used reference&amp;". However, as I said, with use of &amp; you clearly state that you disallow nulls. A caller that knows the dark ways(tm) may only blame himself when your function crashes.</p> <p>disclaimer: "normal" and "the dark ways" are just buzzwords to hide extra complexity of a real professional explanation. If you play a bit with casting and */&amp; operators, you will quickly discover how to get i.e. "int&amp; boom" that would point to a zero-address. This is not so "dark" nor "magic", it's plain feature of the language and platform. However, (A) novice programmers and even somewhat experienced programmers tend to not know that references can be null, and (B) the convention of &amp;-means-dont-pass-null is really well known and settled, so (A+B) please adapt to the convention and feel free to use it where adequate.</p>
 

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