In the following code I made a clone of an for_each
function defined in <algorithm>
(I believe). The only problem is for the third argument which is a void function I made, I get the no matching function for call....unresolved overloaded function type. Could someone shed some light on this matter?
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
void fill(int& n) { //The custom made function, a simple rewrite,
if (n < 100) //which is why I passed an int reference
n = 100;
}
template <class Iterator, class Function> //Clone for_each
void clone_for_each(Iterator first, Iterator last, Function f) {
while( first != last) {
f(*first);
first++;
}
}
int main (int argc, char const* argv[])
{
//Just inputing data and printing it out
//This part is fine up until...
int n;
cout << "Unesite broj vrsta artikala: ";
cin >> n;
vector<string> names;
vector<int> quantity;
cout << "Unesite naziv artikla potom njegovu kolicinu: " << endl;
for (int i = 0; i < n; i++) {
string name;
int amount;
cout << "Unesite naziv: ";
cin >> name;
cout << endl;
cout << "Unesite kolicinu: ";
cin >> amount;
cout << endl;
names.push_back(name);
quantity.push_back(amount);
}
cout << "Raspolozivi artikli: " << endl;
vector<string>::iterator itNames = names.begin();
vector<int>::iterator itQuantity = quantity.begin();
for(itNames, itQuantity; itNames != names.end(), itQuantity != quantity.end(); itNames++, itQuantity++ )
cout << *itNames << " " << *itQuantity << endl;
cout << "Artikli nakon dopune: " << endl;
//right here, which is where I called for clone_for_each
clone_for_each(quantity.begin(), quantity.end(), fill);
return 0;
}