no size yet for forward reference for nested structures

qqiang via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 14 02:43:24 PST 2015


On Wednesday, 14 January 2015 at 08:31:13 UTC, Ali Çehreli wrote:
> First a reminder that this sort of question is more suitable to 
> the D.learn newsgroup.
>
> On 01/13/2015 10:41 PM, qqiang wrote:
>
> > The following code:
> > ```D
> > template PowerHeap(T) {
> >      import std.container : SList;
> >
> >      private alias PowerForest = SList!PowerNode;
> >
> >      private final class PowerNode {
> >          ...
> >      }
> >
> >      final class PowerHead {
> >          ...
> >      }
> > }
> >
> > unittest {
> >      PowerHeap!int h;
> > }
> > ```
>
> I started with your code and produced the following one:
>
> template PowerHeap(T) {
>     import std.container : SList;
>
>     private alias PowerForest = SList!PowerNode;
>
>     private final class PowerNode {
>         // ...
>     }
>
>     final class PowerHead {
>         // ...
>     }
> }
>
> unittest {
>     PowerHeap!int h;    // <-- Compilation error here
> }
>
> void main()
> {}
>
> > failed to compile and get the error: PowerHeap!int.PowerNode:
> no size
> > yet for forward reference.
>
> What compiler and version are you using? I received a different 
> error with the git head dmd:
>
>   Error: PowerHeap!int is used as a type
>
> The compiler is right, PowerHeap!int is a template 
> instantiation that wraps a number of definitions. Did you mean 
> one of those? The following compiles:
>
> unittest {
>     PowerHeap!int.PowerHead h;    // <-- now compiles
> }
>
> > I've googled and found no straightforward solution to this
> issue. The
> > how can I modify my code to eliminate this error?
>
> Please provide exact code so that... Oh, wait! I've just 
> noticed that your error message has PowerHeap!int.PowerNode in 
> it. Let me try with that:
>
> unittest {
>     PowerHeap!int.PowerNode h;    // <-- this compiles as well
> }
>
> Yeah, please provide exact code. :)
>
> Ali

Thanks for your reminder.

I'm sorry that I've provided wrong code. This is the exact code:

-------------------------------------------------------------------

template PowerHeap(T) {
     import std.container : SList;

     private alias PowerForest = SList!PowerNode;

     private final class PowerNode {
         private {
             T payload_;
             uint rank_;
             PowerForest children_;
         }
     }

     final class PowerHeap {
         private {
             PowerNode top_;
             PowerForest forest_;
             uint size_;
         }
     }
}

unittest {
     PowerHeap!int h;
}

----------------------------------------------------------------------
My compiler is v2.066.1


More information about the Digitalmars-d mailing list