std::ref
का उपयोग करने का सही तरीका क्या है? मैं VS2010 में कोड निम्नलिखित की कोशिश की और यह संकलन नहीं करता है:std :: ref का उपयोग कैसे करें?
#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>
using namespace std;
struct IsEven
{
bool operator()(int n)
{
if(n % 2 == 0)
{
evens.push_back(n);
return false;
}
return true;
}
vector<int> evens;
};
int main(int argc, char **argv)
{
vector<int> v;
for(int i = 0; i < 10; ++i)
{
v.push_back(i);
}
IsEven f;
vector<int>::iterator newEnd = remove_if(v.begin(), v.end(), std::ref(f));
return 0;
}
त्रुटियाँ:
c: \ प्रोग्राम फ़ाइलें (x86) \ माइक्रोसॉफ्ट विजुअल स्टूडियो 10.0 \ vc \ शामिल \ xxresult (28): त्रुटि C2903: 'परिणाम': प्रतीक न तो एक वर्ग टेम्पलेट है और न ही एक फ़ंक्शन टेम्पलेट
सी: \ प्रोग्राम फ़ाइलें (x86) \ माइक्रोसॉफ्ट विजुअल स्टूडियो 10.0 \ vc \ include \ xxresult (28): त्रुटि C2143: वाक्यविन्यास त्रुटि: गायब ';' पहले '<'
प्लस कुछ और ...
यह साथ संकलित जी ++ (4.6 और 4.8 दोनों)। – kennytm
@nabulke: यहां तक कि सी ++ 11 में भी? मैंने सोचा कि यह काम करना चाहिए .. – Asha