[fpc-pascal] generics class hierarchy
David Emerson
dle3ab at angelbase.com
Sun Dec 19 02:51:13 CET 2010
Sven Barth wrote:
> I've now looked at your example code in more detail (I was working the
> last time I wrote you). Where did you define "_t_point"? I only found a
> "t_point" in your second mail.
_t_point is part of the template list.
I guess it's a limitation. Conceptually it doesn't seem that different to be
specifying a class to inherit from in the template list, but the compiler isn't
handling it yet.
> Would you please post (or at least attach) your complete test unit? In
> the meantime I'll try to test it with the code pieces you wrote.
unit genericstest;
{$mode objfpc}
interface
uses
classes,
sysutils;
type
generic gt_point <_num> = class
f_left, f_top : _num;
procedure set_lt (l, t : _num); virtual;
end;
type
generic gt_box<_t_point,_num> = class (_t_point) // FAILS :-(
f_width, f_height : _num;
end;
t_real_point = specialize gt_point<single>;
t_special_real_point = class (t_real_point)
procedure set_lt (l, t : single); override;
end;
implementation
procedure gt_point.set_lt (l, t : _num);
begin
f_left := l;
f_top := t;
end;
procedure t_special_real_point.set_lt (l, t : single);
begin
inherited;
end;
end.
More information about the fpc-pascal
mailing list