【发布时间】:2014-03-23 13:44:00
【问题描述】:
难道这不能用 C++11 实现吗?
使用当前的 clang 编译器(OS X 10.8 上的 Xcode 5)编译失败:
std::max_element(group->GetComponents().begin(), group->GetComponents().end(),
[](auto a, auto b) { return a.length > b.length; });
错误信息是: Stuff.cp:68:40: 'auto' 不允许在函数原型中
【问题讨论】:
-
函数参数类型不能是
auto。无法推断类型。 -
Shouldn't this be possible with C++11?这就是C++11 and the Lack of Polymorphic Lambdas - Why? 地址。 -
@RSahu 在这个特定的上下文(模板算法)中,它可以从集合的类型中推断出来,对吧?