Compilable Recursive Data Structure ( was: Recursive data structure using template won't compile)
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Sat Nov 10 05:08:29 PST 2012
On Sat, 10 Nov 2012 10:33:39 +0000 (UTC)
Manfred Nowak <svv1999 at hotmail.com> wrote:
> Nick Sabalausky wrote:
>
> > I really don't see the relevance
>
> Please look at the definition of R:
> struct R
> {
> int value;
> d_list!R Rlist;
> }
>
> If no recursion was wanted the OP should have written:
> d_list!(R*) Rlist;
>
Ok, I see what you're saying, but you're mistaken: That line "d_list!R
Rlist;" is not a problematic recursion.
Imagine if d_list had been defined like this:
struct d_list(T)
{
int i;
}
Then would this still be problematic recursion?:
struct R
{
d_list!R Rlist;
}
No, because R is never actually used anywhere in that d_list (only
int is used). In this case, R is nothing more that part of the *name* of
a particular instantiation of the d_list template.
And indeed, just like the above example, the OP's definition of d_list
also does *not* use R:
struct d_list( T )
{
node* head;
node* tail;
}
Now, yes, that "node" type does use R (instead of R*), *but* "head"
and "tail" are merely pointers to "node", so it's ok.
> In digitalmars.D.learn:40990 I already asked for an explanation.
>
Actually, my newsreader is kinda shitty, and (AFAIK) doesn't give me
any way to lookup a message by ID, so I'm not really sure which message
you're referring to :/
More information about the Digitalmars-d-learn
mailing list