[fpc-pascal] generics class hierarchy
David Emerson
dle3ab at angelbase.com
Thu Dec 16 21:58:53 CET 2010
I'll give a little more detail...
Right now I have these non-generic types:
t_point = class
f_left, f_top : longint; // so named for descendents
// several fields and methods to manage it as I need
end;
t_box = class (t_point)
f_width, f_height : longint;
// more fields and methods to manage it as I need
end;
They've been great.
Now I have need for a point and box that use real coordinates. The structure
would be identical -- simply replacing "longint" with "single" -- which is why
I thought generics would be perfect.
However, t_box inherits from t_point, and this appears to be a sticking point.
My code looks like this:
generic gt_point<_num> = class
f_left, f_top : _num;
// other fields, methods
end;
generic gt_box<_t_point,_num> = class (_t_point)
f_width, f_height : _num;
// other fields, methods
end;
t_real_point = specialize gt_point<single>;
t_real_box = specialize gt_box<t_real_point,single>;
Thanks all!
~David.
More information about the fpc-pascal
mailing list