Lambdas似乎不适用于VS2010中的ref类(Lambdas don't appear to work within ref classes in VS2010)

编程入门 行业动态 更新时间:2024-10-26 03:23:28
Lambdas似乎不适用于VS2010中的ref类(Lambdas don't appear to work within ref classes in VS2010)

Visual Studio 2010中的一个很酷的新C ++特性是lambda表达式。 但是,我无法让他们在托管类中工作。

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 = [](){ ; }; } };

我最好的猜测是编译器创建匿名函数类作为朋友类,尽管我从不使用类成员。 这似乎意味着在ref类中不能使用lambda表达式。

当我读到VS2010将Lambda表达式添加到C ++时,我非常高兴。 有人知道如何让他们在裁判职位内工作吗?

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?

最满意答案

看起来它正在考虑未来的版本。 否则被称为:“我们会去的。”

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

更多推荐

本文发布于:2023-08-02 17:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378315.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   Lambdas   classes   work   ref

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!