在托管 C++ 中声明枚举的正确方法 2005年?
如果我使用 /clr:oldSyntax ,以下内容应该有效:
public __value enum IceCreamFlavors
{
Vanilla,
Chocolate,
Sardine,
};
非 oldSyntax 中的等效项是什么? 如何在 .NET 2.0 的托管 C++ 中声明“托管”枚举?
编辑: 当我遵循 JaredPar 的建议时,然后,如果我尝试将 IceCreamFlavor 传递给具有签名的函数:
OrderFlavor(IceCreamFlavors flav)
通过运行,
OrderFlavor(IceCreamFlavors::Sardine)
我会收到错误:
'IceCreamFlavors Sardine' : member function redeclaration not allowed
If I use /clr:oldSyntax the following should work:
public __value enum IceCreamFlavors
{
Vanilla,
Chocolate,
Sardine,
};
what is the equivalent in non-oldSyntax? How do I declare a "managed" enum in Managed C++ for .NET 2.0?
Edit:
when I follow JaredPar's advice, then if I try to pass an IceCreamFlavor to a function with the signature:
OrderFlavor(IceCreamFlavors flav)
by running
OrderFlavor(IceCreamFlavors::Sardine)
I get the error:
'IceCreamFlavors Sardine' : member function redeclaration not allowed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
您是否有机会尝试在另一个类中声明您的枚举?
即:
如果是,我猜您需要将其移出,以便它成为自己的类而不是嵌套的类。 (托管 C++ 是否允许嵌套类?)我的印象是,您过去可以在另一个类中以非托管方式执行此操作,但由于现在它有自己的类,因此您可能不应该嵌套它们。 我可能错了。 我对托管 C++ 和 C# 的了解有点薄弱。
Are you, by any chance, trying to declare your enum inside another class?
ie:
If you are, I would guess that you need to move it out so that it is its own class instead of a nested one. (Does managed c++ allow nested classes?) My impression is that you used to be able to do it unmanaged style inside another class, but since its its own class now, you probably shouldn't be nesting them. I might be wrong. My knowledge of managed c++ and c# is kind of weak.