list21.backwards

simon.hodson at hssnet.com simon.hodson at hssnet.com
Tue Jun 20 09:36:20 PDT 2006


I'm playing with lists as an alternative to arrays and have come across a
problem:

module people;
private import std.stdio;
private import list;

class Person
{
mixin List; // Turn the Person class into a linked list.

char[] name,tname;
ubyte age;

this(char[] name, ubyte age){this.name = name;this.age = age;}
}

int main()
{
Person.ListHead people,others;

foreach(Person p; people.each)
{
writefln("Person %s is %d years old", p.name, p.age);
}

writefln("---");

foreach(Person p; others.each.backwards)
{
writefln("Person %s is %d years old", p.name, p.age);
}

return 0;
}


produces:

C:\list21>testing6
---
Error: Access Violation

C:\list21>

So iterating over a list is OK provided you don't try to reverse it. I'm
guessing this is an error in the library but not sure how to fix it.  Anyone got
an idea?

Simon





More information about the Digitalmars-d-learn mailing list