c++ - error C3499: a lambda that has been specified to have a void return type cannot return a value -
i using following lambda , getting error. can't figure out why compiler doesn't doing.
std::string captchaword(6, 0); std::generate(captchaword.begin(), captchaword.end(), []() { unsigned int num = randomizer('z' - 'a' + 1 + '9' - '0' + 1); char ch = num + 'a'; if (num >= 'z' - 'a' + 1) { ch += '0' - 'z' - 1; } return ch; });
by way, randomizer function following signature:
unsigned int randomizer(unsigned int);
this error message get:
error c3499: lambda has been specified have void return type cannot return value.
you have specify return type:
[]() -> char { // code; }
the automatic deduction works if whole lambda consists of single return statement only (in c++11), otherwise, need specify type. see documentation on lambda on cppreference. in c++14, rules allow other statements before return.
Comments
Post a Comment