关于编译Lambda时报告返回的为void的错误
2013-10-10 22:01
120 查看
这个错误的信息是这样的:
报告错误的lambda的写法大概是这样:
这个lambda在gcc下编译没有问题,在vc10下就会报上面的那个错误。
可以换成这种写法就OK了。
至于为什么,看这个解释:
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
otherwise,
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; else return 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.
相关文章推荐
- 关于编译Lambda时报告返回的为void的错误
- 关于ADS编译错误 error U1077 C:/Program 返回0x01 的解决办法
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
- 关于Linux下C编译错误(警告)cast from 'void*' to 'int' loses precision
- 【C/C++】关于编译错误 "error C2146: syntax error : missing ';' before identifier 'xxx'"
- 关于ARM交叉编译工具出现:assertion fail elf32-arm.c:12387 的错误解决办法。
- 关于KEIL V4.24.00.0编译提示L121错误的解决方案
- 关于CppUnit单元测试的一些编译错误以及改正
- 关于在windows下使用mingw并行编译wxwidgets时的错误
- 关于VC2008编译出现错误“error C2664: ” 的处理方法:
- 关于l ibrary not found for -lz.1.2.3 编译错误
- asp.net关于控件运行返回错误:必须放在具有 runat=server 的窗体标记内,解决办法。
- iOS错误报告中关于崩溃地址的分析
- STM8 编译错误:PANIC! VOID
- linux编译mysql关于mysql.sock的错误
- 关于C#操作PPT时遇到的“对COM组件的调用返回了错误HRESULT E_FAIL”错误的解决方法
- 关于Qt编译前的错误提示(一)
- Linux系统平台下关于GCC编译及使用的方法(-Werror,它要求GCC将所有的警告当成错误进行处理 )
- 关于Visual Studio 2013 编译 multi-byte character set MFC程序出现 MSB8031 错误的解决办法
- [内核源码][编译] 关于openssl/opensslv.h错误的解决方案