Skip to main content
GameDev.net gamedev.net
🔒 Locked

Pointers

Started by Ataru Mar 15, 2003 at 11:06 PM 5 replies 1.1k views
Original Post
Ataru
Ataru
Maybe I''m just tired but I can''t seem to get this to work. Here''s some pseodocode of my problem. File 1. game_object *items[1000]; foo() { insert(items[0]); } File 2 struct node { game_objects *inserted[5]; int numObj=0; }; //Node is properly initialized, memory is allocated void insert(game_object* &toInsert) { tst->inserted[0] = toInsert; printf("%d %d",toInsert->x,toInsert->y); } When I try to acess toInsert (via the printf) the program crashes. For some reason tst->inserted[0] does not point to the same address as items[0] (which is what I want). Maybe I''ll figure it out in the morning, but I always get these stupid pointer things wrong. Any help is appreciated.
RabidChild
RabidChild
Maybe you should just declare your insert function like this:

void insert(game_object * toInsert)
{
.
.
.
}

without the & .
--Ben CarterRomans 8:38-39
Ataru
Ataru
No, that''s what I tried first. When it didn''t work I figured I had to send the pointer to the address but still no go.
Alpha_ProgDes
Alpha_ProgDes

struct node
{
game_objects *inserted[5];
int numObj=0;
};

//Node is properly initialized, memory is allocated
void insert(game_object* &toInsert)
{
tst->inserted[0] = toInsert;
printf("%d %d",toInsert->x,toInsert->y);
}


it should be (i think)

void insert(game_objects **toInsert)
{
tst->inserted[0] = **toInsert; // assigning values not addresses
printf("%d %d", *toInsert->x, toInsert->y);
}


i don''t have my book in front of me but i think that''s 80% right,
i think.
Beginner in Game Development?  Read here. And read here.  
Ataru
Ataru
Still a no go. You have to pass the address of course so it would be:

insert(&items[0]);

insert(game_node **obj) ...

but the same thing happens. I don''t want to pass the value. I just want an array of pointers pointing to instantiated objects. Ugh, it should work.
Alpha_ProgDes
Alpha_ProgDes
Take a look at this. it may might drop a lightbulb

also have you tried this:

&(tst)->inserted[0] = toInsert;

try it with and without the parenthesis.

hope you figure this out soon.
Beginner in Game Development?  Read here. And read here.  
Ataru
Ataru
Or I could have really been tired (I wasn''t kidding) and not realized that I was actually passing the equiv of items[0+1] and therefore passing a NULL pointer to insert.

Lol, thanks for the help everyone

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.