繁体   English   中英

C ++(Builder XE7)枚举类型属性错误行为

[英]C++ (Builder XE7) enum type property misterious behaviour

我不是C ++专家,但是需要将旧项目更新到Embarcadero C ++ Builder XE7。

此代码无法编译(fpFixed行):

#include <System.UITypes.hpp>
...
NewText->Font->Pitch = fpFixed;

间距是:

__property System::Uitypes::TFontPitch Pitch = {read=GetPitch, write=SetPitch, default=0};
void __fastcall SetPitch(const System::Uitypes::TFontPitch Value);

enum class DECLSPEC_DENUM TFontPitch : unsigned char { fpDefault, fpVariable, fpFixed };

错误:“ E2451未定义符号'fpFixed'”

另外两次尝试:

NewText->Font->Pitch = TFontPitch.fpFixed;
NewText->Font->Pitch = System::Uitypes::TFontPitch.fpFixed;

两者均出错:E2108 typedef'TFontPitch'的使用不当

但这很奇怪-编译时没有警告:

System::Uitypes::TFontPitch( fpFixed );   // yes,no assignments here just an unused value
NewText->Font->Pitch = fpFixed;

这是什么解释,我在这里做错了吗? 只是经过反复试验才得出这个“解决方案”。

NewText-> Font-> Pitch = TFontPitch.fpFixed;
NewText-> Font-> Pitch = System :: Uitypes :: TFontPitch.fpFixed;

您这样做的方向正确,但是使用了错误的语法。 使用::代替.

NewText->Font->Pitch = TFontPitch::fpFixed;
NewText->Font->Pitch = System::Uitypes::TFontPitch::fpFixed;

这在Embarcadero的DocWiki中有记录:

强类型枚举(C ++ 0x)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM