no size yet for forward reference for nested structures

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 14 00:31:13 PST 2015


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



More information about the Digitalmars-d mailing list