开发者

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

开发者 https://www.devze.com 2022-12-17 21:23 出处:网络
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.

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 t开发者_开发技巧he 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消