I''ve never had problems with pointers before, but for some dumb reason this doesn''t work, and I''m a little tired of it.
Here''s what I have, in an easy to read example.
objects *gameObj[MAX_OBJ];
objects *selected;
void foo()
{
selected = NULL;
select(selected);
}
void select(objects * selected)
{
for (int i = 0; i < MAX_OBJ; i++) {
if (obj_selected)
selected = gameObj;
}
}
Basically I want selected to point to the selected object, whichever it is. Before calling select() selected is NULL, inside select(), selected is not NULL, but after returning selected is NULL again.
Now if I understand my pointers, when selected points to the smae location, unless I make gameObj[i] NULL, it should point to that object always. It''s probably one dumb thing I''m missing, but for the life of me, I can''t figure out what it is.
Thanks
As far as I can see the problem is that the pointer 'selected' that you set to NULL in foo() and the pointer 'selected' that you use as the parametre for select() are two separate entities...what you need to do I think is pass by reference...ie: void select(object* &selected)...
[edited by - HashMaster on January 25, 2003 12:41:05 PM]
It''s not really global in my implementation. Just needed to declare it as an example. Thanks, master, that should work. I''m going to go test it now. I figured that was the problem, just didn''t know how to solve it.
Thanks again
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more