Richard said:
what is the syntax for returning a vector?
temp is a vector
return temp; ?
return temp<>; ?
return temp<int>; ?
I got a book that does not talk about how to do this. Any helps are
appreciated.
Presumably you mean something like this:
vector<int> GetVec()
{
vector<int> v;
// Do something here to fill the vector
return v;
}
The problem is that this function returns by value, which means the
vector will likely be copied in its entirety, which could get expensive
unless your compiler can figure out that it doesn't need to copy it
(but I wouldn't depend on that). Alternately, you could pass the vector
in by reference:
void GetVec2( vector<int>& v )
{
// You might need to check to see if v holds anthing on entry
// (existing elements might be fine or might not be)
// Do something here to fill/change the vector
}
Now, no copying is involved no matter what optimizations you use.
There are some other techniques, too, but this latter one is probably
what you want.
Cheers! --M