【发布时间】:2021-03-07 08:21:32
【问题描述】:
我想在 pascal 中实现两种记录类型的交叉类型对话。但我收到错误“错误:预期的过程或功能”。这是相关代码:
{$mode objfpc}{$H+}
interface
{$modeswitch advancedrecords}
uses
Classes, SysUtils;
type
TRGBA8 = packed record
r,
g,
b,
a: byte;
public
constructor Create(r_in, g_in, b_in, a_in: byte);
end;
TRGBA16 = packed record
r,
g,
b,
a: word;
public
constructor Create(r_in, g_in, b_in, a_in: word);
class operator Explicit(const c_in: TRGBA16): TRGBA8; inline;
class operator :=(const c_in: TRGBA16): TRGBA8; inline;
end;
TRGBA8Helper = record helper for TRGBA8
public
class operator Explicit(const c_in: TRGBA8): TRGBA16;
end;
我在声明 TRGBA8Helper 的 Operator Explicit 时收到错误消息。如何归档交叉类型的对话。提前致谢。
我正在使用来自 Ubuntu 存储库的 Lazarus 1.8.2 和 FPC 3.0.4。
【问题讨论】:
-
类和记录助手不支持运算符重载,至少在 Delphi 中不支持。您将不得不在帮助程序中声明一个函数。
标签: operator-overloading record pascal helper freepascal