Memory leak with dynamic array
bearophile
bearophileHUGS at lycos.com
Sun Apr 11 19:36:50 PDT 2010
> But those list-like data structures probably can't be defined using the normal array literals :-)
I was wrong, this is not so bad looking:
struct List(T) {
// Node of std.range.SListRange is not static!
static struct Node {
T data;
Node* next;
this(T d, Node* p=null) {
data = d;
next = p;
}
}
Node* lh;
this(T[] arr) {
foreach_reverse (el; arr)
lh = new Node(el, lh);
}
}
void main() {
List!int items = [1, 2, 3];
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list