C3499 a lambda that has been specified to have a void return type cannot return a value
Posted on 2013-04-16 13:35 Roger Luo 阅读(348) 评论(0) 编辑 收藏 举报出现这个错误基本由于Lambda中没有显示地说明返回值类型,而是由编译器自己推断返回值。下面是从C++11官方文档中抄过来的
If a lambda-expression does not include a trailing-return-type, it is as if the trailing-return-type denotes the following type:
-
If the compound-statement is of the form
{ return expression ; }
the type of the returned expression after lvalue-to-rvalue conversion (4.1), array-to-pointer conversion (4.2), and function-to-pointer conversion (4.3); -
otherwise,
void
.
如果lambda的主体中有多句语句,建议将其返回类型声明,否则编译器将会自行推断返回值,从而导致编译失败。
lambda添加返回值格式为:
[...] (...) mutableopt throwSpecopt ->retTypeopt {...}