संकलन के नीचे "समाधान" संकलित करता है लेकिन यह वही नहीं है जो मैं चाहता हूं। मैं put
सदस्य फ़ंक्शन को for_each
और *this
पर पास करना चाहता हूं। बूस्ट का उपयोग एक विकल्प नहीं है। क्या इसे सी ++ 03 के भीतर हल किया जा सकता है?सी ++ 03 में कोई_एक कार्य करने के लिए सदस्य फ़ंक्शन पास करना (कोई बढ़ावा नहीं, कोई सी ++ 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