对于以下代码:
struct B
{
void g()
{
[]() { B::f(); }();
}
static void f();
};
Run Code Online (Sandbox Code Playgroud)
g ++ 4.6给出错误:
test.cpp:在lambda函数中:
test.cpp:44:21:错误:这个lambda函数没有捕获'this'
(有趣的是,g ++ 4.5编译代码很好).
这是g ++ 4.6中的错误,还是真的有必要捕获'this'参数才能调用静态成员函数?我不明白为什么会这样,我甚至认可了这个电话B::.
Mik*_*son 44
我同意,它应该编译得很好.对于修复(如果您还不知道),只需添加引用捕获,它将在gcc 4.6上正常编译
struct B
{
void g()
{
[&]() { B::f(); }();
}
static void f() { std::cout << "Hello World" << std::endl; };
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25455 次 |
| 最近记录: |