[fpc-pascal] Correct way to write generic type aliases
leledumbo
leledumbo_cool at yahoo.co.id
Sun Aug 28 21:15:01 CEST 2016
I want my in-project units depend on a single in-project unit which abstracts
the actual used out-project units. i.e. instead of:
MyUnit1 -> RTLUnit
MyUnit2 -> RTLUnit
I want it to be:
MyUnit1 -> RTLAbstractorUnit
MyUnit2 -> RTLAbstractorUnit
RTLAbstractorUnit -> RTLUnit
So I try to write:
unit DataStructures;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Generics.Collections;
type
// Error: Identifier not found "TObjectList"
TMyList = TObjectList;
// Error: Identifier not found "T"
generic TMyList<T> = specialize TObjectList<T>;
generic TMyList<T: class> = specialize TObjectList<T>;
// Unhandled EAccessViolation followed by Error: Compilation raised
exception internally
generic TMyList<T> = class(specialize TObjectList<T>);
generic TMyList<T: class> = class(specialize TObjectList<T>);
generic TMyList<T: class> = class(specialize TObjectList<T>) end;
implementation
end.
but neither of above seems to work. What is the correct way to write generic
type aliases? Even if it's not real alias like the last 3, as long as it's
working, I'm OK.
--
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Correct-way-to-write-generic-type-aliases-tp5726179.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
More information about the fpc-pascal
mailing list