no size yet for forward reference for nested structures

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 14 07:09:44 PST 2015


On 01/14/2015 02:53 AM, ketmar via Digitalmars-d wrote:

 > On Wed, 14 Jan 2015 10:41:07 +0000
 > qqiang via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
 >
 >> 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;
 >> }
 > there is a circular dependency in your data structures. you're defining
 > `PowerNode` in the terms of... `PowerNode`. this won't work.
 >
 > your `PowerForest` definition depends of complete `PowerNode`
 > definition, but `PowerNode` definition depends of complete
 > `PowerForest` definition.
 >
 > don't do that.
 >

Reduced:

import std.container;

class Node
{
     SList!Node children;
}

void main()
{}

Error: class deneme.Node no size yet for forward reference

I wonder why an SList of a reference type requires the size of the 
elements? The following compiles but is that a pointer to a class 
variable or a class object? How can we even use the 'children' member?

     SList!(Node*) children;

Ali



More information about the Digitalmars-d mailing list