Fle*_*exo 14 c++ lambda linkage c++11
这似乎适用于我尝试过的平台:
#include <iostream>
// extern "C" linkage
extern "C" void foo(void (*fn_ptr)(int));
namespace {
struct bar {
static void f(int);
};
}
int main() {
// Usually works on most platforms, not guaranteed though:
foo(bar::f);
// Probably equally bad or worse?
foo([](int x) { std::cout << x << std::endl; });
}
Run Code Online (Sandbox Code Playgroud)
但是当不需要时,再次传递一个静态成员函数也可以在这些平台上运行.
有没有办法强制lambda有合适的链接,使这个安全和便携?还是已经?