Re: STL Vector - pass by reference?
Ben Voigt [C++ MVP] wrote:
:: "David Wilkinson" <no-reply@effisols.com> wrote in message
:: news:eR1GUla3HHA.4584@TK2MSFTNGP03.phx.gbl...
::: Gerry Hickman wrote:
:::: I guessed 'returns' should be a comment, but the first two lines
:::: didn't make sense with void following vector<string>::size_type,
:::: I guess I was supposed to _replace_ void with
:::: vector<string>::size_type, seems obvious now.
:::
:::: Does this only apply to the 'pointer' version, or does it apply
:::: to the 'references' version too?
:::
::: Gerry:
:::
::: The "void" is Doug's post was a typo, I think. This confused me
::: also.
:::
::: When you pass a pointer, the "implication" is that it could be
::: NULL, and that the function will take some special action in this
::: case. If you pass a reference, it cannot be NULL (every reference
::: must be initialized to some object), so no such action need be
::: taken.
::
:: This "every reference must be initialized to some object" is not
:: true. Any pointer can be converted to a reference.
::
But you can't convert the pointer to an invalid reference, without
invoking undefined behavior. Then it's your problem.
Bo Persson