मेरे पास निम्न प्रोग्राम है जो lambda फ़ंक्शन के साथ ptr_fun का उपयोग करता है।ptr_fun एक लैम्ब्डा फ़ंक्शन के साथ
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string target="aa";
vector<string> v1;
v1.push_back("aa");
v1.push_back("bb");
auto stringcasecmp=[](string lhs, string rhs)->int
{
return strcasecmp(lhs.c_str(), rhs.c_str());
};
auto pos = find_if(
v1.begin(), v1.end(),
not1(bind2nd(ptr_fun(stringcasecmp), target))
);
if (pos != v1.end())
cout << "The search for `" << target << "' was successful.\n"
"The next string is: `" << pos[1] << "'.\n";
}
मुझे निम्न त्रुटि संदेश मिलते हैं।
stackoverflow.cpp: In function ‘int main()’:
stackoverflow.cpp:21:41: error: no matching function for call to ‘ptr_fun(main()::<lambda(std::string, std::string)>&)’
stackoverflow.cpp:22:6: error: unable to deduce ‘auto’ from ‘<expression error>’
मैं इसे संकलित करने के लिए कोड (न्यूनतम) कैसे संशोधित करूं?
बस एक छोटे से sidenote: यदि आप एक तरह एक लैम्ब्डा के प्रयोग पर योजना बना रहे हैं आप यहाँ एक बहुत, तुम हो सकता है संदर्भ के रूप में तर्क पारित करने पर विचार करें। स्ट्रिंग प्रतिलिपि के बहुत से बचाओ। –
आपको लगता है कि आपका 'स्ट्रिंगकेसंप' लैम्ब्डा रिकर्सिव है! – quamrana
@quamrana यह रिकर्सिव क्यों है? – ggg