Return value for recursive program

Hi, I am writing a recursive program to return two indices of a vector whose values add up to a target value. I want to pack two such indices in a vector and return it. I don't know the best way to do it. Here's the program that does it. I am returning such vector<int> vResult, but the program is designed such that I need to have it in the parameter list too. How can I eliminate this parameter and pass only as a return value?

Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
vector<int> TwoSum(vector<int>& numbers, int remaining, int part, int currIndex, vector<int> vResult)
{
    if(part > 2)
    {
      return vResult;
    }
    if (part == 2 && rem == 0)
    {
      return vResult;
    }
    for(int i = currIndex, i < numbers.size(); ++i)
    {
      vResult.push_back(currIndex);
      remaining -= numbers[currIndex];
      auto vTmp = TwoSum(numbers, remaining, ++part, ++currIndex, vResult);
      if(!remaining)
        return vTmp;
      else
      {
        remaining += numbers[currIndex];
        vTmp.pop_back();
      }
    }
}
Topic archived. No new replies allowed.