Passing multiple vectors to a function

How do I pass more than one vector to a function?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Prototype
void getNum (std::vector<int> *numbers);

int main()
{
   std::vector<int> numbers, morenumbers;
   getNum(&numbers);
   return 0;
}

void getNum(std::vector<int> *numbers)
{
   int array[2] = {1,7};
   numbers->assign (array, array+2);
}


This works fine, builds the vector the same as the array but I dont get how I can pass more than one vector to the getNum function, I am unsure of the syntax any ideas?
Last edited on
Consider std::vector<std::vector<int>>.

Plan B: You pass a pointer to function. Pointer points to a memory location. Where does a pointer+1 point to?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Prototype
void getNum (std::vector<int>&,std::vector<int>&);

int main()
{
   std::vector<int> numbers, morenumbers;
   getNum(numbers);
   return 0;
}

void getNum(std::vector<int> &newNumbers,std::vector<int> &newmoreNumbers)
{
   int array[2] = {1,7};
   newNumbers.push_back (array, array+2);
}


Ok I have it working but are the parameters too long or is this the shortest way to do it?
Last edited on
Topic archived. No new replies allowed.