Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 629
Daniel Wolf Avatar asked Nov 06 '22 17:11

Daniel Wolf


1 Answers

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

like image 87
GManNickG Avatar answered Nov 17 '22 09:11

GManNickG