की स्पष्ट वापसी प्रकार जब मैं कोशिश करते हैं और इस कोड (VS2010) मैं निम्न त्रुटि हो रही है संकलन: error C3499: a lambda that has been specified to have a void return type cannot return a value
लैम्ब्डा
void DataFile::removeComments()
{
string::const_iterator start, end;
boost::regex expression("^\\s?#");
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
// Look for lines that either start with a hash (#)
// or have nothing but white-space preceeding the hash symbol
remove_if(rawLines.begin(), rawLines.end(), [&expression, &start, &end, &what, &flags](const string& line)
{
start = line.begin();
end = line.end();
bool temp = boost::regex_search(start, end, what, expression, flags);
return temp;
});
}
मैं लैम्ब्डा एक 'शून्य' वापसी प्रकार है कि निर्दिष्ट किया कैसे। अधिक से अधिक, मैं कैसे निर्दिष्ट करूं कि लैम्ब्डा में 'बूल' रिटर्न प्रकार है?
अद्यतन
निम्नलिखित संकलित करता है। क्या कोई मुझे बता सकता है कि क्यों संकलित करता है और दूसरा नहीं करता?
void DataFile::removeComments()
{
boost::regex expression("^(\\s+)?#");
boost::match_results<std::string::const_iterator> what;
boost::match_flag_type flags = boost::match_default;
// Look for lines that either start with a hash (#)
// or have nothing but white-space preceeding the hash symbol
rawLines.erase(remove_if(rawLines.begin(), rawLines.end(), [&expression, &what, &flags](const string& line)
{ return boost::regex_search(line.begin(), line.end(), what, expression, flags); }));
}
आप स्पष्ट रूप से 'यह निर्दिष्ट कर सकते हैं ->', उदा '[&] (डबल डी) -> डबल {// ...' – Flexo
मैं आपको सलाह देता हूं कि आपको केवल वही चर (केवल '[&] ...') पर कब्जा कर लें, जैसा कि आपके पास वर्तमान में है अनावश्यक रूप से verbose। – Xeo
@Xeo क्या आप मुझे बता सकते हैं कि इसका वर्बोज़ क्यों? मुझे लैम्ब्डा में क्या, अभिव्यक्ति और झंडे की ज़रूरत है और यही वह है जिसे मैंने कब्जा कर लिया है। मैं किस कटौती काट सकता हूं? – Ryan