i write follow code:
static int count = []()->int
{
int count = 0;
for(int i = 0; i < categories.size(); ++i)
{
if(!categories[i].isCategory())
{
count++;
}
}
return count;
};
and got error:error: cannot convert '__lambda0' to 'int' in initialization
.
does the meaning of my code fragment is assign the __lambda0
to static int count
instead of return the inner count?
You aren't calling it! Make sure you do so:
static int count = []()->int
{
int count = 0;
for(int i = 0; i < categories.size(); ++i)
{
if(!categories[i].isCategory())
{
count++;
}
}
return count;
}();
// ^^ THIS THIS THIS THIS
BUT, IMHO, you're better off in this without using a lambda. And in the case where you'd use it in other parts of your code, then have it in a stand-alone (not lambda) function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With