I'm new to the STL and am trying to learn from (dear Lord) the web...at any rate I want to use generate to populate a vector with numbers within a range. Tutorials seem to lead me to code like this, but the compiler always coughs up a "term does not evaluate to a function" error at the function in the generate statement. Can someone point me in the right direction?
Code:
#include<vector>
#include<algorithm>
#include<iostream>
#include<cstdlib>
using namespace std;
class randomInt{
public:
randomInt(int i, int j) : min(i), max(j) {}
int operator()(int min, int max){
return rand()%(max-min)+min;
}
private:
int min, max;
};
int main(){
vector<int> v(50);
randomInt ri(10,50);
generate(v.begin(), v.end(), ri);
for(vector<int>::iterator i = v.begin(); i != v.end(); ++i){
cout << *i << " ";
}
return EXIT_SUCCESS;
}
Comment