Re: Syntax of int Array in Message (OT: Objective-C Forum)
Re: Syntax of int Array in Message (OT: Objective-C Forum)
- Subject: Re: Syntax of int Array in Message (OT: Objective-C Forum)
- From: glenn andreas <email@hidden>
- Date: Tue, 16 Jan 2007 10:53:43 -0600
On Jan 16, 2007, at 10:31 AM, Jason Barker wrote:
- (id)initWithArray:(int[])array
[snip]
The problem I am having is when I pass an int array in the init
message, I get the following warning: passing argument 1 of
'initWithArray:' from incompatible pointer type
However, when I pass the int array to the object with the
'resetWithArray:' message, it does not have this warning.
The reason is that the code:
[[IntMatrix alloc] initWithArray: int_C]
is calling "initWithArray:" on the return value of alloc.
Alloc returns an id, so the compiler sees this as:
id someObject = [IntMatrix alloc];
[someObject initWithArray: int_C];
It decides that you must mean NSArray's "initWithArray:" which takes
an NSArray *, not an int[], and this the warning. (You should
probably also be getting a warning about ambiguous methods).
The best thing to do is to change your init method to
"initWithIntArray:" and the problem will go away (since it will no
longer clash with NSArray's, as well as being more like the standard
name conventions).
Alternately, you could write [(IntMatrix *)[IntMatrix alloc]
initWithArrray: int_C]
Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures,
fractals, art
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden