Hi,
I missed the key point. This bug should be fixed in 2.7.1, but I am now using 2.6.0. Now there is another problem:
If I change my code to this:
TTreapEnumerator = class
FStack: TStack;
FCurrent: PNode;
public
* constructor Create(root: PNode);*
destructor Destroy; override;
function MoveNext: Boolean;
property Current: PNode read FCurrent;
end;
The problem is gone, because PNode is not a generic class, but only a record. However, the following errors are generated:
Error: Forward declaration not solved "constructor THistogram.TTreap$Char$LongInt.TTreapEnumerator.Create(PNode);" Error: Forward declaration not solved "destructor
THistogram.TTreap$Char$LongInt.TTreapEnumerator.Destroy;" Error: Forward declaration not solved
"THistogram.TTreap$Char$LongInt.TTreapEnumerator.MoveNext:Boolean;"
THistogram is defined as:
THistogram = class(specialize TTreap<Char, Integer>)
protected
function DefaultTraverser(Key: Char; Value: Integer): Boolean; override;
procedure DefaultDisposer(Value: Integer); override;
function DefaultUpdater(Key: TKey; Value: TValue; IsNew: Boolean):
Boolean; override;
public
MKey: Char;
Max: Integer;
constructor Create; override;
end;
I think there is no need to define TTreapEnumerator in THistogram again, right?
Xiangrong
2013/3/22 Xiangrong Fang
Show quoted text 55 lines
Hi,
I try to do exactly the same as show here:
QUOTE:
http://svn.freepascal.org/svn/fpc/trunk/packages/fcl-stl/src/gvector.pp
generic TVector<T> = class
... ...
type
TVectorEnumerator = class
private
FVector: TVector;
FPosition: SizeUInt;
FFirstDone: Boolean;
function GetCurrent: T; inline;
public
*constructor Create(AVector: TVector);*
function MoveNext: Boolean; inline;
property Current: T read GetCurrent;
end;
... ...
public
My code:
generic TTreap<TKey, TValue> = class
... ...
type
TTreapEnumerator = class
FStack: TStack;
FCurrent: PNode;
public
*constructor Create(ATreap: TTreap);*
destructor Destroy; override;
function MoveNext: Boolean;
property Current: PNode read FCurrent;
end;
... ...
private
Error message I got is: Error: Generics without specialization cannot be used as a type for a variable
Then I found this:
http://bugs.freepascal.org/view.php?id=19499&history=1
I wonder if this bug's fix is release or not? How does the TVector class compile with this problem?
Thanks!
Xiangrong