问题描述:variable 'XXX cannot be implicitly captured in a lambda with no capture-default specified
今天在日常刷题的时候,使用了lambda函数。
具体是在一个lambda匿名函数里面使用了另一个lambda函数,然后会报错:
报错:
Line 46: Char 22: error: variable ‘isAlpha’ cannot be implicitly captured in a lambda with no capture-default specified
解决:
原因是函数也是一个对象,需要进行捕获。上面的匿名函数isValid没有捕获另一个匿名函数isAlpha,因此报错,只需要在isValid的捕获列表中该为[=] 或者 [&]即可。