Re: STL Vector - pass by reference?
"Ulrich Eckhardt" <eckhardt@satorlaser.com> wrote in message
news:tp06p4-ile.ln1@satorlaser.homedns.org...
Gerry Hickman wrote:
void PopulateStrings(vector<string> * guids)
{
guids->clear();
guids->push_back("test1");
guids->push_back("test2");
}
While this code will work, there is one thing I object to: in C++, where
you have references, a pointer[1] means to me that something is
optional,
i.e. passing zero is okay, but you don't mean that. Still, you must
handle that case, so either you just return (making it a non-error),
throw an exception (making it a runtime error) or use assert() (making
it
a programmer's error).
Does this only apply to the 'pointer' version, or does it apply to the
'references' version too?
A reference can't be null, so this doesn't apply.
That's not true. It's illegal to use a null reference, but in the same way
that it's illegal to use a null pointer.