以下の「解決策」はコンパイルされますが、私の望むものではありません。 put
メンバ関数をfor_each
に渡し、*this
には渡しません。ブーストを使用すると、にはのオプションがあります。これはC++ 03で解決できますか?C++ 03のfor_eachにメンバー関数を渡す(ブーストなし、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;
}
なぜ正確に説明できますか? – EmeryBerger