Objective-C pointer to pointer?

btoth

Person that uses a Mac
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.
 
Figured it out, that works, my problem was it being a NULL pointer when it was called -awakeFromNib:, that was dumb.
 
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 :).
 
Back
Top