相关疑难解决方法(0)

lambdas需要捕获'this'来调用静态成员函数?

对于以下代码:

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::.

c++ lambda c++11

56
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

c++11 ×1

lambda ×1