I try to create manually and explicit an interetable single linked list of floats. Probably one of the most basic datastructures.

import std.stdio;
void main(){
        struct List {
                struct Node {
                        float f;
                        Node *next;
                        }
                Node * root=null;
                bool empty() const {return !root;}
                void popFront() {root=root.next;}
                float front() const {return root.f;}
                void push(float f) {
                                Node * newnode=new Node();
                                newnode.f=f;
                                root.next=newnode; // Segmentation fault
                                }
        }
        List * l=new List();
        l.push(3);
        foreach(element;l){ // Invalid foreach aggregate
          writeln(element.root.f);
        }
}

But I have a segmentation fault and an invalid foreach aggregate

Reply via email to