Are function-local typedefs visible inside C++0x lambdas?

后端 未结 4 962
既然无缘
既然无缘 2021-01-11 13:27

I\'ve run into a strange problem. The following simplified code reproduces the problem in MSVC 2010:

template 
struct dummy
{
    static T f         


        
4条回答
  •  再見小時候
    2021-01-11 14:13

    Function-local enums cannot be detected by lambdas either.

    int main()
    {   
        enum E {A, B, C};   
        auto x = [](){ int a = A; }; 
        //auto y = [](){ E a = A; }; // this will crash the compiler
    }
    

    error C3493: 'A' cannot be implicitly captured because no default capture mode has been specified

    Following is a workround, problematic-maybe though.

    int main()
    {   
        enum E {A, B, C};   
        auto x = [=](){ int a = A; };
        // typedef E F; 
        // auto y = [=](){ F a = A; }; // this compiles ok
    }
    

提交回复
热议问题