Consider the situation when you are developing a library that has its API declared in the header files and implementation in the source files. This library shall have a function that accepts any functional objects. Take a look at the following code:
// making a typedef for function pointer accepting int // and returning nothing typedef void (*func_t)(int); // Function that accepts pointer to function and // calls accepted function for each integer that it has. // It cannot work with functional objects :( void process_integers(func_t f); // Functional object class int_processor { const int min_; const int max_; bool& triggered_; public: int_processor(int min, int max, bool& triggered) : min_(min) , max_(max) , triggered_(triggered) {} void operator()(int i) const { if (i < min_ || i > max_) { triggered_ = true; } } };
How do you change...