Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
When would you want to use a pointer of a pointer? I see it in Cocoa and some other Objective-C & C frameworks and it really doesn't make sense to me.

Let's say I ask you write a function that calculates two integer values and returns them. How would you write this function?

Now I ask you to write a function that find three NSString* values and returns them, let's say a function where I give you an NSString* with English text, and you should return three NSString* containing the same text in German, Italian and French. What would the function declaration look like?
 
I am learning pointers in my book and had the same question too. Why can't you just send message to an objects method to return the instance variable? Chown33 showed me this link this morning and it shed light on pointers. gnasher729 response is still way above my skill level I and could not do that.

http://masters-of-the-void.com/book5.htm

-Lars
 
Two dimensional arrays is one example, or if you need to manipulate the pointer itself inside a function. In such a case you need a pointer pointing to the pointer, since sending in the original pointer will only give you a local copy, where changes is not seen outside the scope.
 
Let's say I ask you write a function that calculates two integer values and returns them. How would you write this function?

Now I ask you to write a function that find three NSString* values and returns them, let's say a function where I give you an NSString* with English text, and you should return three NSString* containing the same text in German, Italian and French. What would the function declaration look like?

Im rather proud of myself, that didn't fly over my head. :D
 
In Cocoa a common usage is passing an NSError **. This allows a brand new NSError object to be returned, as otherwise if an NSError * was passed in it would be unusable as it is immutable.

Outside of Objective-C there are many times that this comes up, most of which have already been listed. It's probably impossible to make an exhaustive list, because it's all just data and how to get to it.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.