Keeping list of Objects

Hasan Aljudy hasan.aljudy at gmail.com
Fri Apr 28 00:44:19 PDT 2006


Jeremy wrote:
> 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.
> 

That's probably because you come from a C++ background.
I think that if you're used to Java, then you won't make this mistake.

Anyway, in D, objects (of classes) are always by reference, never by 
value!! never!

structs default to by-value, but if they are an inout parameter in a 
function, I believe they will be references.

> 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