出现这个错误基本由于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 {...}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2021-12-02
  • 2021-05-30
  • 2021-07-12
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2021-12-01
  • 2021-07-18
  • 2021-06-03
  • 2022-01-30
  • 2021-07-16
  • 2021-11-13
相关资源
相似解决方案