【发布时间】:2017-03-27 18:57:54
【问题描述】:
这个问题和这个one有关。
为什么不编译:
int main() {
auto foo = [&]() -> int {foo; return {};}();
(void)(foo);
}
错误:
main.cpp: In lambda function:
main.cpp:3:30: error: use of 'foo' before deduction of 'auto'
auto foo = [&]() -> int {foo; return {};}();
^~~
但是将 foo 转换为结果类型允许编译:
int main() {
auto foo = [&]() -> int {int(foo); (void)(foo);return {};}();
(void)(foo);
}
【问题讨论】:
-
我不明白。
foo是一个返回int的 lambda,而不是int... 你是不是要调用 lambdaauto foo = [&](){...}();? -
@YSC 抱歉,正在编辑。