[fpc-pascal] Generics

Damien Gerard milipili at shikami.org
Mon Mar 31 16:07:12 CEST 2008


Le Mar 31, 2008 à 3:59 PM, ik a écrit :
> Can you create a small proof of concept, and attach it here ?
>

Here you are.
The unit is in development so it may remain some errors (I would like  
to convert another units with the use of generics).

BTW, is there a way to specifiy the template parameter must be a  
descendant of another class ?

> Ido
>
> On Mon, Mar 31, 2008 at 4:27 PM, Damien Gerard  
> <milipili at shikami.org> wrote:
>>
>> Le Mar 31, 2008 à 3:00 PM, Damien Gerard a écrit :
>>
>>>
>>> I would like to make a generic class, like this :
>>>
>>> {$mode objfpc}
>>>
>>> generic TMCollection<_T> = class(TObject)
>>> private
>>>   FDefaultItem: _T;  // line 35
>>> public
>>>   constructor Create;
>>>   destructor Destroy;override;
>>>   [...]
>>> end;
>>>
>>>
>>> But I have got the following :
>>> commons.pas(35,21) Error: Identifier not found "_T"
>>> commons.pas(35,21) Error: Error in type definition
>>> commons.pas(39,34) Error: Identifier not found "_T"
>>> commons.pas(44,84) Error: Identifier not found "_T"
>>>
>>> According to the documentation, I should use `var private`, but I
>>> have got :
>>>
>>> Compiling ./commons.pas
>>> commons.pas(33,3) Error: VAR and TYPE are allowed only in generics
>>> commons.pas(35,21) Error: Identifier not found "_T"
>>>
>>> Could someone tell me where I am wrong ?
>>> Thanks !
>>>
>>
>>
>>
>> I forgot : fpc 2.2.0 and fpc 2.2.1. May be I should upgrade to  
>> 2.3.x ?



-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.pas
Type: application/octet-stream
Size: 4290 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20080331/259d80ee/attachment.obj>
-------------- next part --------------




--
Damien Gerard
milipili at shikami.org

"Intelligence is 10 million rules."
    -- Douglas Lenat







More information about the fpc-pascal mailing list