以下代码是可以编译通过的。但是否存在任何悬空引用问题呢?
class Foo {
Foo(std::function<void(int)> fn) { /* etc */ }
}
void f(int i, Foo& foo) { /* stuff with i and foo */ }
Foo foo([&foo](int i){f(i, foo);});
看起来能够工作。(当然,真正的Lambda函数会更复杂。)