2、使用成员函数实现二进制函数重载的示例
现有类IntDate,代码如下:
type IntDate=class
value;
function create(v)
begin
value:=v;
end
function operator DateToStr()
begin
v:=IntToDate(value);
return DateToStr(v);
end
end
其中,创建了成员函数DateToStr,实现了对二进制函数DateToStr的重载。
调用方式如下:
d:=new IntDate(20240329);
return DateToStr(d);
结果:返回字符串"2024-03-29"