Just don't use pointers, not even smart ones in this case:
std::vector<string> MyFunction1()
{
std::vector<string> arrayOfStrings;
MyFunction2(arrayOfStrings); // work with arrayOfStrings
return arrayOfStrings;
}
void MyFunction2(std::vector<string> &array)
{
array.push_back("foo string");
}
The compiler will surely optimize the return value copy away, applying an optimization called Return Value Optimization, so you shouldn't worry about that. Using pointers, in this case, to avoid copying will probably end up being more inefficient and tedious to work with, compared to using objects allocated on the stack and relying on this optimization.
Otherwise, consider using std::unique_ptr
as @templatetypedef mentions. Avoid pointers whenever you can.