I have a function that returns an array like this:
vector<string> GetString()
{
vector<string> s;
s.push_back("one");
s.push_back("two");
s.push_back("three");
return s;
}
and I'm calling it in this way:
vector<string> mystrings=GetStrings();
I can implement it as follows too:
void GetString(vector<string> & s)
{
s.push_back("one");
s.push_back("two");
s.push_back("three");
}
and call it in this way:
vector<string> mystrings;
GetStrings(mystrings);
Which one is better?
Does version one copy a vector to another? If yes then it is slow if the vector is big.