# Objective-C pointer to pointer?



## btoth (Oct 4, 2004)

I was trying to have a pointer that pointed to another pointer that points to the instance of an object... such that:

Object *instancePtr = [[Object alloc] init];
Object **ptrToInstancePtr = &instancePtr;

Then I was trying to send a message like:

[*ptrToInstancePtr message];

But is seemed to just crash with a memory error of some sort.  Should this work? Or was I going about it the wrong way?  What I want is the pointer to the pointer so that if the object that 'instancePtr' points to changes, I don't need to update ptrToInstnacePtr.


----------



## kermit64 (Oct 4, 2004)

just use
[instancePtr message]

whatever instance pointer points to will receive the message


----------



## btoth (Oct 4, 2004)

Figured it out, that works, my problem was it being a NULL pointer when it was called -awakeFromNib:, that was dumb.


----------



## kermit64 (Oct 4, 2004)

cool, how did you solve it?
did you just check for null first or something more creative?


----------



## Viro (Oct 4, 2004)

You could easily just insert an assert statement. Like assert(ptrToInstancePtr != NULL) and you'll catch it if it was a NULL pointer. Recovering from that is going to be a lot harder, of course .


----------

