|
Prev: declaration of an incomplete private type before the private part
Next: access assignation. Aliasing problems?
From: Niklas Holsti on 1 Feb 2008 03:49 Javi wrote: > My problem: I need to do a declaration such as: > > ----------------------------------------- > ... > type ListNode is private; > type List is private; > > package IterList is new Iterators (Creator => List, > Item => ListNode, > getFirst => Lists.getFirst, > getNext => Lists.getNext, > isLast => Lists.isLast); > > function makeIter (L : List) return IterList.Iterator; > ... > private: > (complete declaration of ListNode and List) > ----------------------------------------- > > > The problem is that I need to complete the type (ListNode and List) > before instancing the new package. But I do not know how to do that! > The only solution I have found is to declare the types non-private and > then give them the complete declaration. Obviously, this solution does > not satisfy me since I want to make the types private. As I understand it, you want to instantiate the Iterators package before the "private" part, because you want to use the type Iterator, defined in the instance, in the declaration of public oeprations (makeIter). One way to work around this problem is to define a new type for that purpose: type ListNode is private; type List is private; type ListIterator is private; -- Added. function makeIter (L : List) return ListIterator; private type ListNode is ... -- Complete declaration. type List is ... -- Complete declaration. packate IterList is new Iterators (....); -- As above. type ListIterator is new IterList.Iterator; HTH, -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ . |