无法捕获具有嵌套lambda的静态成员 [英] Cannot capture static member with nested lambda

查看:110
本文介绍了无法捕获具有嵌套lambda的静态成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套lambda函数的问题,它看不到静态类成员。

I have a problem with a nested lambda function which cannot see a static class member. Visual Studio 2010 gives me a C2065 ( undeclared identifier ) for reasons I cannot understand.

这里是一个简单的例子,突出了我的问题:

Here is simple case that highlights my problem:

#include <algorithm>
#include <vector>

using namespace std;

struct foo
{
    void do_some()
    {
        std::vector<int> a;
        std::vector<int> b;

        for_each( a.begin(), a.end(), [&] ( const int& m )
            {
                // works
                auto j = _i + 1;

                for_each( b.begin(), b.end(), [&] ( const int& n )
                    {
                        **// doesn't work**
                        auto k = _i + 1;
                    } );
            } );
    }

    static int _i;
};

int main(int argc, char* argv[])
{
}

任何人都知道我做错了什么?

Anyone knows what I'm doing wrong?

谢谢,
Christian

Thanks, Christian

推荐答案

可能是一个编译器错误(在VC ++ 2012中修复)。这工作原理:

Probably a compiler bug (fixed in VC++ 2012). This works:

auto k = ::foo::_i + 1;

这篇关于无法捕获具有嵌套lambda的静态成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆