In STL, the syntax for Fill is template void fill (ForwardIterator first, ForwardIterator last, const T& val);
The third parameter in the below program should be int. What does it imply by the statement operator int() const? Can we have int as a function name? How does the return value of this function get converted to int and stored in a vector(As in third parameter of fill function)?
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void print(int v) {
cout << v << ", ";
}
struct Sequence {
int start;
Sequence(int a,int b): start(a) { }
Sequence(int start) :start(start) {}
operator int() const{
return start;//LINE I
}
};
int main() {
vector<int> v1(7);
fill(v1.begin(), v1.end(), Sequence(1,2));//LINE II
for_each(v1.begin(), v1.end(), print);
return 0;
}