Function object: Difference between revisions

Content deleted Content added
No edit summary
C++Bro123 (talk | contribs)
m Maintaining state: Improve C++ example
Line 138:
 
<source lang=Cpp>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <algorithm>
 
class CountFrom {
public:
private:
CountFrom(int & count;) : count_(count) {}
public:
CountFrom(int &noperator() : count(n) { return count_++; }
 
int operator()() { return count++; }
private:
int& count_;
};
 
int main() {
{
int state(10);
std::generate_n(std::ostream_iterator<int>(std::cout, "\n"), 11,
CountFrom(state));
return 0;
}
</source>