I am trying to return a pointer to std::vector
from a function as follows:
std::vector<int>* find_solution(const std::vector<int>& list)
I tried the following solutions:
const std::vector<int>* find_solution(const std::vector<int>& list)
and
vector<int>* find_solution(const std::vector<int>& list)
{
//populate solution_list
std::vector<int>* return_list = new std::vector<int>;
return_list = &solution_list;
}
where solution_list
is the name of the local vector I would like to return a pointer to. Neither of them worked, the returned vector is always empty. Any tips would be greatly appreciated, but keep in mind that the program calling this function needs to be able to manage the vector in memory. In other words, returning the vector object is not a viable solution. Thanks!