[fpc-pascal] generics class hierarchy

Honza befelemepeseveze at gmail.com
Sun Dec 19 08:34:23 CET 2010


2010/12/19 David Emerson <dle3ab at angelbase.com>:
> type
>  generic gt_box<_t_point,_num> = class (_t_point)   // FAILS :-(
>   f_width, f_height : _num;
>   end;

I think it should fail according to the docs, see:

http://www.freepascal.org/docs-html/ref/refse42.html

"There is a single placeholder _T. It will be substituted by a type
identifier when the generic class is specialized. The identifier _T
*may not be used for anything else than a placehoder*. "

The bold part is IMO violated by the declaration. Anyway, it could be
perhaps (not tested) written as:

type
  TBoxProxy = class(_t_point);
  generic gt_box<_t_point, _num> = class(TBoxProxy)
    f_width, f_height : _num;
  end;

Another strange point is, that the declaration of gt_box doesn't use
the formal specialization paramater `_t_point` at all (in the posted
code), so the same the other way around should also work:

type
  generic gt_box<_num> = class<_t_point>
    f_width, f_height : _num;
  end;

A 3rd note is that your code can't compile as _t_point is not declared
when gt_box is declared, but the declaration wants to inherit from
_t_point, so IMO also for this the code is rightfully rejected the
compiler.

HTH
-- 
bflm
freepascal-bits.blogspot.com



More information about the fpc-pascal mailing list