Lambda 似乎不适用于 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 = [](){ ; };
}
};
我最好的猜测是,编译器将匿名函数类创建为友元类,即使我从不使用类成员。这似乎意味着 lambda 根本不能在 ref 类中使用。
当我读到 VS2010 在 C++ 中添加了 lambda 表达式时,我非常高兴。有人知道如何让他们在参考课中工作吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来正在考虑将其用于未来版本。也称为:“我们会做到的。”
Looks like it is being considered for future versions. Otherwise known as: "We'll get to it."