La "soluzione" di seguito viene compilata ma non è quello che voglio. Vorrei passare la funzione membro put
a for_each
e non a *this
. L'utilizzo di boost è NON un'opzione. Può essere risolto in C++ 03?Passare una funzione membro a for_each in C++ 03 (senza boost, no C++ 11)
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
class Wheel { };
class Car {
public:
void process(const vector<Wheel>& wheel) {
for_each(wheel.begin(), wheel.end(), *this);
}
void operator()(const Wheel& w) { put(w); }
private:
void put(const Wheel& w) { }
};
int main() {
vector<Wheel> w(4);
Car c;
c.process(w);
return 0;
}
Potrebbe spiegare perché esattamente? – EmeryBerger