现有整数类IntDate,代码如下:
type IntDate=class
value;
function create(v)
begin
value:=v;
end
class function operator DateToStr(t)
begin
t:=ifObj(t)?t.value:t;
endt:=IntToDate(t);
return DateToStr(endt);
end
end
其中,创建了类方法DateToStr,实现了对二进制函数DateToStr的重载。
在调用时,可以使用如下两种方式:
d:=new IntDate(20240329);
return DateToStr(d); //方式一
return class(IntDate).DateToStr(20240329); //方式二
结果:返回字符串"2024-03-29"