What you're looking to do is a C++ism, it's not available in Objective- C; there's no explicit support for pass by reference.

It's certainly possible to achieve the same ends though. For primitive types, you'll have to pass a pointer. Declare the method as taking, for example 'int *' if you want to pass a pointer-to-int, and call it by taking the address of the thing you want to pass a pointer to (e.g. use '&myInt' if 'myint' is the primitive you want to pass by reference).

For Obj-C objects, 'pass by reference' effectively always happens, because you have to pass a pointer to the object (like an 'NSMutableString *') anyway.

Jamie.

On 10 Dec 2008, at 15:53, Nick Rogers wrote:

Hi, thanks for the reply.
Now I have:

- (UInt32)traverseTreeStraightReturnedDirection:(&int)treeDirection
            returnedTreeDepth:(&int)treeDepth
              returnedKey:(&HPlusCatalogKey)catKey
               lookForKey:(HPlusCatalogKey)lastKey
{
// code here
}

Still the same error: parse error before & token

Thanks,
Nick

On 10-Dec-08, at 9:15 PM, Dave DeLong wrote:

Put the & before the variable type:

- (UInt32) traverseTreeStraightReturnedDirection: (&int)treeDirection...

HTH,

Dave

On Dec 10, 2008, at 8:43 AM, Nick Rogers wrote:

Hi,
I have the following in my .m file:


- (UInt32)traverseTreeStraightReturnedDirection:(int&)treeDirection
          returnedTreeDepth:(int&)treeDepth
            returnedKey:(HPlusCatalogKey&)catKey
             lookForKey:(HPlusCatalogKey)lastKey
{
// code here
}

But the error when compiling is "parse error before & token".
Is passing by reference not allowed or is there any other syntax that I should follow?

Thanks,
Nick
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/roger_s1%40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jamie%40montgomerie.net

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to