我想用隐式类型转换实现2个记录结构:
TMyRecord1=record
X, Y: Integer;
//other fields specific to TMyRecord1
class operator Implicit(const Rec: TMyRecord2): TMyRecord1; //<- problem: TMyRecord2 undeclared
end;
TMyRecord2=record
X, Y: Real;
//other fields specific to TMyRecord2
class operator Implicit(const Rec: TMyRecord1): TMyRecord2;
end;
class operator TMyRecord1.Implicit(const Rec: TMyRecord2): TMyRecord1;
begin
Result.X:=Round(Rec.X);
Result.Y:=Round(Rec.Y);
end;
class operator TMyRecord2.Implicit(const Rec: TMyRecord1): TMyRecord2;
begin
Result.X:=Rec.X;
Result.Y:=Rec.Y;
end;
问题是循环引用。
实施此方法的最佳方法是什么?