[ create a new paste ] login | about

Link: http://codepad.org/v7oRd5jM    [ raw code | output | fork ]

lenniedg2000 - C++, pasted on Oct 1:
#include <iostream>
#include <vector>

template <class VectorT>
void ForEach(vector<VectorT>& vec,
             void (*forEachFunction)(vector<VectorT>&)) 
{ 
  forEachFunction(vec); 
} 

void change(vector<int>& ages)
{
  for(int i = 0; i < (int) ages.size(); i++)
  {
   ages[i] = 1;
  }
}

int main()
{
  vector<int> ages;
  ages.push_back(5);
  ages.push_back(10);
  ForEach(ages, change);
  
  for (int i = 0; i < (int) ages.size(); i++)
  {
    cout << ages[i] << endl;
  }
  return 0;
}


Output:
1
2
1
1


Create a new paste based on this one


Comments: