Forum > General

problem with generic: identifier not found [solved]

(1/1)

webcss:
Hi,

I've some problems to implement a generic class. interface looks like this:

--- Code: ---type
  generic TGStorableList<_T_> = class
  private
    function  GetCurrent: _T_;
    function  GetItem(Index: integer): _T_;
    procedure SetItem(Index: integer; const AValue: _T_);
    ....

--- End code ---
compiler throws an exception "identifer not found: _T_"
I tried different visibilities for the Get.../Set... methods, but exception remains.
I'm using fpc2.5.1

what can I do/avoid?

Leledumbo:
On which line does the compiler choke?

webcss:

--- Quote from: Leledumbo on April 27, 2010, 10:32:46 am ---On which line does the compiler choke?

--- End quote ---
function  GetCurrent: _T_; <-- here, e.g. the first line the generic placeholder is referred to

webcss:

--- Quote from: webcss on April 27, 2010, 07:25:27 am ---Hi,

I've some problems to implement a generic class. interface looks like this:

--- Code: ---type
  generic TGStorableList<_T_> = class
  private
    function  GetCurrent: _T_;
    function  GetItem(Index: integer): _T_;
    procedure SetItem(Index: integer; const AValue: _T_);
    ....

--- End code ---

--- End quote ---
well, I missed a forward declaration to the generic class  ::)

To achive my goal I simply introduced a generic class inheriting my TGStorableList, e.g.


--- Code: ---TGStorableList=class
....
code
....
end;
[b]generic[/b] TGenericStorableList<_T_>=class(TGStorableList)
....
{change relevant routines to support _T_ }
....
end;

--- End code ---
Just for the ones encountering the same problems  :)

eny:
There's no problem here: the compiler works as specified.
But for the record: I use the same mechanism (mainly for specialized object lists).

Navigation

[0] Message Index

Go to full version