How to declare a parameterized recursive data structure?

artemav via Digitalmars-d digitalmars-d at puremagic.com
Fri Aug 15 12:13:38 PDT 2014


:) Wow, thanks for all replies. I realized too late that should 
write "that's it".
Hmm, It's also a good sign that D community is active.


On Friday, 15 August 2014 at 19:01:57 UTC, artemav wrote:
> Sorry, jumped the gun on that.
>
> On Friday, 15 August 2014 at 18:37:52 UTC, artemav wrote:
>> I'm getting an error when trying to compile (DMD64 D Compiler 
>> v2.066) this:
>>
>> struct node(T) {
>>    T data;
>>    node!T next;
>> };
>>
>> void main() {
>>    node!int n;
>> }
>>
>> output:
>> test.d(3): Error: struct test.node!int.node cannot have field 
>> next with same struct type
>> test.d(9): Error: template instance test.node!int error 
>> instantiating
>> ...
>>
>> It is so simple code that the error "... cannot have field 
>> next with same struct type" looks funny and sad at the same 
>> time. Is it a bug or are there some constraints why it cannot 
>> be compiled?



More information about the Digitalmars-d mailing list