Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -25,8 +25,8 @@ procedure Test_Polymorphic_Copy is
-- The function knows nothing about S and creates a copy on the heap
function Clone (X : T'Class) return T_ptr is
begin
return new T'Class(X);
end Copier;
return new T'Class'(X);
end Clone;
package Derived is
type S is new T with null record;
@ -43,8 +43,8 @@ procedure Test_Polymorphic_Copy is
Object_1 : T;
Object_2 : S;
Object_3 : T_ptr := Clone(T);
Object_4 : T_ptr := Clone(S);
Object_3 : T_ptr := Clone(Object_1);
Object_4 : T_ptr := Clone(Object_2);
begin
Copier (Object_1);
Copier (Object_2);

View file

@ -0,0 +1,33 @@
type
Base = class
public
fb: integer;
constructor (fb: integer) := Self.fb := fb;
function ToString: string; override := fb.ToString;
function Clone: Base; virtual := new Base(fb);
end;
Derived = class(Base)
public
fd: real;
constructor (fb: integer; fd: real);
begin
inherited Create(fb);
Self.fd := fd;
end;
function ToString: string; override := inherited ToString + ',' + fd.ToString;
function Clone: Base; override := new derived(fb,fd);
end;
begin
var lst := new List<Base>;
lst.Add(new Base(3));
lst.Add(new Derived(4,5.5));
lst.Add(new Base(6));
lst.Add(new Derived(7,8.8));
lst.Println;
var lst1 := new List<Base>;
foreach var obj in lst do
lst1.Add(obj.Clone);
lst1.Println;
end.