关于编译Lambda时报告返回的为void的错误
生活随笔
收集整理的这篇文章主要介绍了
关于编译Lambda时报告返回的为void的错误
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
这个错误的信息是这样的:
a lambda that has been specified to have a void return type cannot return a value
报告错误的lambda的写法大概是这样:
[] (int a, int b){if (a<b)return true;elsereturn false; };
这个lambda在gcc下编译没有问题,在vc10下就会报上面的那个错误。
可以换成这种写法就OK了。
[](int a, int b){return a<b; };
至于为什么,看这个解释:
The C++11 standard, §5.1.2/4 states:
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.
转载于:https://www.cnblogs.com/pangblog/p/3362294.html
总结
以上是生活随笔为你收集整理的关于编译Lambda时报告返回的为void的错误的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: C/C++中的段错误(Segmentat
- 下一篇: PowerDesigner提示This