Re: STL Vector - pass by reference?

Tech-Archive recommends: Fix windows errors by optimizing your registry




"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:eR1GUla3HHA.4584@xxxxxxxxxxxxxxxxxxxxxxx
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.


Generally, in C++ references are preferred to pointers.

--
David Wilkinson
Visual C++ MVP


.



Relevant Pages

  • Re: Question on LSP
    ... Sure, the developer must keep track of which type has been assigned to each pointer to manage complexity in creating the design, which is why the 'T' is in T*. ... Subtyping is a relation which does not ... Those object types are completely orthogonal to the semantics of being an object reference. ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Question on LSP
    ... Because construction paradigms have different goals. ... But that has nothing to do with what a pointer type ... But that does not mean that the semantics of an object reference is ... aggregate references, is the aggregate of referenced objects or target ...
    (comp.object)
  • Re: Question on LSP
    ... equivalent addresses in the same context. ... Note that the language allows us to use a name like 'T' on the reference as a mnemonic so that the developer can keep track of what is happening with the indirection. ... Modern languages have proper pointer types. ...
    (comp.object)
  • Re: Nothing Keyword Destories Objects rather than just resetting the variable to an empty variable
    ... there is no difference between using ByVal or ByRef. ... as the C1 pointer was the sole reference to the class object. ... Yes, an object variable is a pointer to an object, but that is the only ... the keyword "NOTHING" should only destroy the ...
    (microsoft.public.excel.programming)
  • Re: How java passes object references?
    ... to think of them as being a specific location in a larger block of memory ... Whether a language passes by reference or by value, ... is a pointer pointing at the memory block. ... So when allocating local memory for o, it would simply allocate a ...
    (comp.lang.java.programmer)