The code indeed does not work in FPC, not even trunk because the default keyword for types other than arrays is not (yet) implemented.
(And also not smartpointers, so you have to create/free your object)
That is a NewPascal feature, not FPC.
Your code should have looked something like this:
{$mode objfpc}
type
generic TNullable<T> = class
private
FValue : T;
public
isAssigned : boolean;
function IsNull: boolean;
procedure SetValue (newValue: T);
Property Value : T read FValue write SetValue;
end;
procedure TNullable.SetValue (newValue: T);
begin
FValue := newValue;
isAssigned := true;
end;
function TNullable.IsNull: boolean;
begin
result := not isAssigned;
end;
type
TBoolean = specialize TNullable<boolean>;
Var
bool: TBoolean;
begin
bool := TBoolean.Create;
bool.value := true;
if bool.value then writeln('bool is true');
bool.free;
end.
@Blaazen: that that cast works is only because the first field in the class stores the boolean. I don't think that is what you mean...
