Lambdas don't appear to work within ref classes in VS2010

大城市里の小女人 提交于 2019-12-10 14:27:39

问题


One of the cool new C++ features in Visual Studio 2010 are lambda expressions. However, I can't get them to work within a managed class.

class UnmanagedClass {
    void Foo() {
        // Creating empty lambda within unmanaged class.
        // This compiles fine.
        auto lambda = [](){ ; };
    }
};

ref class ManagedClass {
    void Foo() {
        // Creating empty lambda within managed class.
        // This creates error C3809:
        // A managed type cannot have any friend functions/classes/interfaces.
        auto lambda = [](){ ; };
    }
};

My best guess is that the compiler creates the anonymous function class as a friend class, even though I never use class members. This seems to mean that lambdas cannot be used at all within ref classes.

I was so happy when I read that VS2010 adds lambda expressions to C++. Does anybody know how to get them to work within ref classes?


回答1:


Looks like it is being considered for future versions. Otherwise known as: "We'll get to it."



来源:https://stackoverflow.com/questions/2134978/lambdas-dont-appear-to-work-within-ref-classes-in-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!