Sign in Join

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

Mailing lists / fpc-devel / 2015-05

generics and scoping rules

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Martin Frb

What are the scoping rules?

Example:

   TLazStorageMemBase = object
   private
   const
     CNT_OFFS  = SizeOf(Pointer);
     DATA_OFFS = CNT_OFFS + (2 * SizeOf(Integer));
   private
     FMem: PByte;
     function GetCapacity: Integer; inline;
     function GetCount: Integer; inline;
.....
   end;
   generic TLazGenStorageMem<T> = object(TLazStorageMemBase)
...
     property Capacity: Integer read GetCapacity write SetCapacity;
     property Count: Integer read GetCount;
   end;

If I specialize TLazGenStorageMem in an other unit, then I get tons of errors, because all the privet symbols are not accessible.

Is that intended?

Reply by email

Sven Barth
to Martin Frb
"Martin Frb" wrote 25 lines
What are the scoping rules? Example: TLazStorageMemBase = object private const CNT_OFFS = SizeOf(Pointer); DATA_OFFS = CNT_OFFS + (2 * SizeOf(Integer)); private FMem: PByte; function GetCapacity: Integer; inline; function GetCount: Integer; inline; ..... end; generic TLazGenStorageMem<T> = object(TLazStorageMemBase) ... property Capacity: Integer read GetCapacity write SetCapacity; property Count: Integer read GetCount; end; If I specialize TLazGenStorageMem in an other unit, then I get tons of

errors, because all the privet symbols are not accessible.

Is that intended?

I'd say that this is not intended, but I'll need to retest this with Delphi.

You forgot one very important piece of information though: what compiler version are you using? If it's 2.6.x, then please test with 3.0.1 or 3.1.1 as there were /many/ changes since then and 2.6.4's generic support is nothing compared to what we now have (despite there still being quite some bugs and missing features).

Regards,
Sven

Reply by email