Re: STL Vector - pass by reference?
On Mon, 13 Aug 2007 13:13:18 +0100, Gerry Hickman
<gerry666uk@newsgroup.nospam> wrote:
I was confused by Doug's example, I'd copied it literally
vector<string>::size_type
void GetDeviceClasses(vector<string>& guids)
{
guids.clear();
// If you can estimate n, reserve can eliminate reallocations.
// guids.reserve(n);
...
returns guids.size();
}
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.
Of course, I meant to write:
vector<string>::size_type
GetDeviceClasses(vector<string>& guids)
{
guids.clear();
// If you can estimate n, reserve can eliminate reallocations.
// guids.reserve(n);
...
return guids.size();
}
I'm amazed that no one, including myself, has commented on this before now.
:) I think what happened back in July, when I was replying to your original
thread, is that, I initially had the function returning void, but then I
reviewed your example and saw it would be useful to return the number of
GUIDs that were found. Or maybe I thought, "Hmmm, this function is
essentially an unbounded 'read' function for GUIDs, so why not return the
number read?" Whatever I thought, I followed it up by performing an
unusually sloppy edit. Sorry about that.
--
Doug Harrison
Visual C++ MVP