【问题标题】:C++ (Builder XE7) enum type property misterious behaviourC++(Builder XE7)枚举类型属性神秘行为
【发布时间】:2015-05-11 14:05:28
【问题描述】:

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

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

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

Pitch 在哪里:

__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;

对此有何解释,我在这里做错了吗?只是通过反复试验得出这个“解决方案”。

【问题讨论】:

    标签: properties enums c++builder c++builder-xe7


    【解决方案1】:

    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 中有记录:

    Strongly Typed Enums (C++0x)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-10
      • 2019-03-08
      • 2018-02-04
      • 1970-01-01
      相关资源
      最近更新 更多