Arrays as Parameters?

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
I'm a C/C++ programmer until recently when I found a lot of enjoyment in Cocoa and ObjC, but one thing I can't get is having an array as a parameter to a method. Is this possible in ObjC? I thought it'd look like this - (int)findTotal: (int)hand[] but that gives me an error: BlackjackView.m:118: error: parse error before '[' token. Any help is appreciated.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #2
I don't have time to check, but shouldn't it be:

Code:
- (int)findTotal: (int[])hand

If that doesn't work just pass it as a pointer to an int, then you can just use it like an array anyway.

Code:
- (int)findTotal: (int)*hand
//then somewhere...
hand[5] = 5;

Just be careful not to go out of bounds, but you already new that I'm sure.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #3
Thanks a lot. I'll give them a try.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  C: Global Variables versus Parameters Lizard Man 10 6,624 Jan 13, 2010 08:22 PM
Last Post: Lizard Man