In the actual operation, we often encounter the need to return a sequence of strings or a column of numbers, used to use arrays to save the string or number of this column, now we can use vectors to save the data. However, when the amount of data is very large, the use of vector efficiency is relatively low, and do not return the reference, because you are the vector defined in the function. It is common to use vectors as return values, and we can do that by putting them in function arguments and adding references as containers for saving data. Example:
Original:
vector<int> fun1 (int num);
Better ways to handle:
BOOL FUN1 (int num, vector<int> &vec);
This sets the return value of the function to bool, or saves the data in the VEC, using its reference.
The two methods above can achieve the same effect, but the second method is recommended.
Vector as function return value