Pointers or copies?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Wed Dec 20 14:21:02 PST 2006


Orgoton wrote:
> I'm making a game and I have to keep track of the objects in the game, which
> inherit from a master object class called "objct". So I would make a class for
> "baddie", "player" and such. Now, to draw them I have to keep track of their
> existance, so, when one is created, it adds itself to the "frame queue" and
> removes itself when it is deleted. To keep track of them I created a "queue"
> class, which has a protected member called "objct *pters[]". It is an array of
> pointers so when I recieve a new actor for the queue, I increase the array
> size accordingly and on the next slot, just add it there. Simple. Now, the
> queue class has a method called "add" and "remove" both of them take as
> parameter "objct *target".
> 
> To sum it up and finally tell you my question the objct has in it's
> constructor "framequeue.add(this);" and a correspondind "remove(this)".
> 
> Apparently, "this" is not a pointer... as the compiler claims: "function
> queue.remoce (objct *target) does not match parameter types (objct)" and that
> "cannot implicitly convert expression (this) of type objct to objct*". So,
> does passing "this" create a copy of the object? How do I pass the pointer to
> the object to the queue? Any other solution?

Unless I am missing something, you shouldn't need to use pointers at all.  Object 
variables in D are referances to the actual object which lives off in space somewhere. 
(Where space happens to be the heap.)  I'm also curious as to how this Queue class of 
yours is designed.  It sounds like there ought to be an easier means.

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list