Keeping list of Objects

Jeremy Jeremy_member at pathlink.com
Thu Apr 27 20:11:42 PDT 2006


I fixed my own problem -- I just need not use * and & symbols :)

Sometimes I get confused on to what is actually already made a pointer, and what
is not.

In article <e2ruoi$nv8$1 at digitaldaemon.com>, Jeremy says...
>
>I'm writing a game in D, and in a loop, I'm creating new objects and keeping
>track of them by storing their pointers:
>
>e.g. I have a linked list of pointers. In the loop, I do a "OBJECT newThing =
>new OBJECT()", and then I add the pointer &newThing to the linked list. After
>that function exits (and the scope exits), I try to access these OBJECTs by
>referencing the pointers... but I get an error. I assume the garbage collector
>is freeing that space?
>
>Anyway, I want to do this because I want a linked list of different objects
>(e.g. all the objects in my game, which might be different classes -- I can cast
>these pointers later).
>
>I'm realizing that this won't work (unless I make the newThing global, then the
>data I allocated still exists later). Anyone have a better way of accomplishing
>the same thing?
>
>





More information about the Digitalmars-d mailing list