Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-01

specialization of inner class of generic class

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Frank Fischer

Hi,

I'm a fpc newbie and currently playing around with generic classes. Consider the following code:

===== test.pas =====
{$mode objfpc}
program Test;
type
   generic TGen<_T> = class
   public
   type
      TInner = class
         procedure Func;
      end;
   end;
   TInst = specialize TGen<Integer>;
procedure TGen.TInner.Func;
begin
end;
begin
end.
====================

When I compile this program with fpc 2.6.0 I get the following error:

% fpc test.pas
Free Pascal Compiler version 2.6.0 [2011/12/23] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for i386
Compiling test.pas
test.pas(8,20) Error: Forward declaration not solved "TGen$LongInt.TInner.Func;" test.pas(20) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted

It seems as if the line TInst = specialize TGen<Integer> is not sufficient to specialize the inner class TInner of TGen<Integer>. What do I have to do to get a correct specialization of the inner class?

Thanks in advance and sorry if this is a stupid question.

Frank

Sven Barth
to Frank Fischer
Frank Fischer wrote 5 lines
Hi, I'm a fpc newbie and currently playing around with generic classes. Consider the following code:

[snip]

Show quoted text 14 lines
% fpc test.pas Free Pascal Compiler version 2.6.0 [2011/12/23] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Linux for i386 Compiling test.pas test.pas(8,20) Error: Forward declaration not solved "TGen$LongInt.TInner.Func;" test.pas(20) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted It seems as if the line TInst = specialize TGen<Integer> is not sufficient to specialize the inner class TInner of TGen<Integer>. What do I have to do to get a correct specialization of the inner class? Thanks in advance and sorry if this is a stupid question.

This is not supported with 2.6.0.

It's only supported in trunk (version 2.7.1) since December.

Regards,
Sven