Re: STL Vector - pass by reference?
- From: "Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx>
- Date: Mon, 13 Aug 2007 08:38:25 -0500
"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
.
- Follow-Ups:
- Re: STL Vector - pass by reference?
- From: Doug Harrison [MVP]
- Re: STL Vector - pass by reference?
- From: Bo Persson
- Re: STL Vector - pass by reference?
- References:
- STL Vector - pass by reference?
- From: Gerry Hickman
- Re: STL Vector - pass by reference?
- From: Ulrich Eckhardt
- Re: STL Vector - pass by reference?
- From: Gerry Hickman
- Re: STL Vector - pass by reference?
- From: David Wilkinson
- STL Vector - pass by reference?
- Prev by Date: Re: STL Vector - pass by reference?
- Next by Date: Re: Share .cpp and .h along projects
- Previous by thread: Re: STL Vector - pass by reference?
- Next by thread: Re: STL Vector - pass by reference?
- Index(es):
Relevant Pages
|