{$define virtual} {$N+} {$R+} uses crt; type PT = ^T; T = object constructor create; destructor done;{$ifdef virtual} virtual;{$endif} end; PTint = ^Tint; Tint = object(T) value: integer; procedure init(X: integer); procedure print; {$ifdef virtual} destructor done; virtual; {$endif} end; PTfloat = ^Tfloat; Tfloat = object(T) value: double; procedure init(X: double); procedure print; {$ifdef virtual} destructor done; virtual; {$endif} end; constructor T.create; begin end; destructor T.done; begin end; procedure Tint.init(X: integer); begin value := X end; procedure Tint.print; begin write(value:4) end; {$ifdef virtual} destructor Tint.done; begin end; {$endif} procedure Tfloat.init(X: double); begin value := X; end; procedure Tfloat.print; begin write(value:8:4) end; {$ifdef virtual} destructor Tfloat.done; begin end; {$endif} const maxSize = 100; type TArr = object arr: array[1 .. maxSize] of PT; num:byte; constructor init; destructor done; function set_index(const p: PT):boolean; procedure count_each(const p: PT); end; constructor TArr.init; var i:byte; begin num:=0; for i:=1 to maxSize do arr[i]:=nil; end; destructor TArr.done; var i:byte; begin for i:=1 to num do dispose(arr[i],done); end; function TArr.set_index(const p: PT):boolean; begin inc(num); if num<= maxSize then begin arr[num]:=p; set_index:=true; end else begin dec(num); dispose(p,done); set_index:=false; end; end; procedure TArr.count_each(const p: PT); var i, count: integer; begin count := 0; for i := 1 to num do if (typeof(arr[i]^) = typeof(p^)) then inc(count); writeln('count = ', count); dispose(p,done); end; var obj_int: PTint; obj_float:PTfloat; any_arr: TArr; mem:longint; i:byte; begin clrscr; mem:=memavail; any_arr.init; obj_int := new(PTint,create); obj_int^.value := 3; any_arr.set_index(obj_int); for i:=1 to 150 do begin obj_float := new(PTfloat,create); obj_float^.value := 3.5; any_arr.set_index(obj_float); end; any_arr.count_each(new(PTfloat,create)); any_arr.done; writeln('Difference : ',mem-memavail); readln; end.