Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)

Rob T rob at ucora.com
Fri Nov 9 21:29:02 PST 2012


If anyone is interested, here's my current work-a-round ...

// original code that fails ...

struct R
{
    int value;
    d_list!R Rlist;
}

// d-linked list with templated payload
struct d_list( T )
{
    struct node
    {
       T payload;
       node* pred;
       node* succ;
    }
    node* head;
    node* tail;
}

// modified code that works ...

// no changes made
struct R
{
    int value;
    d_list!R Rlist;
}

// definition moved out of d_list
struct node( T )
{
    T payload;
    node* pred;
    node* succ;
}

// Added default type N = node!(T)
struct d_list( T, N = node!(T) )
{
    N* head;
    N* tail;
}

Thanks again for all your help!

--rt


More information about the Digitalmars-d-learn mailing list