Re: newbie question initWithCapacity
Re: newbie question initWithCapacity
- Subject: Re: newbie question initWithCapacity
- From: Philippe Mougin <email@hidden>
- Date: Sun, 5 Jan 2003 17:13:11 +0100
> I can't begin to see how this can happen, how can a method
> of NSString.h be used in a class which has no relation with it
> whatsoever ?
When the compiler warns you that there are multiple declarations for
initWithCapacity:, it is in the process of compiling the invocation of
the initWithCapacity: method. In order do to so, it use the type
information found in the declaration of this method (return type, type
of the argument). Note that the compiler job is not to decide which
method implementation will be called at run-time (since Objectective-C
messaging use dynamic binding, the compiler doesnt know which
implementation will be called), but to decide which declaration to use
in order to compile the code that invoke this method. The compiler
issues this warning because it has found multiple declarations of
initWithCapacity: that have different *signatures* (i.e. a different
return type or argument type). This is a problem for the compiler
because, as Karl explained in his answer, and as stated in the
Objective-C manual, "except for messages sent to statically typed
receivers, dynamic binding requires all implementations of identically
named methods to have the same return type and the same argument types.
(Statically typed receivers are an exception to this rule, since the
compiler can learn about the method implementation from the class
type.)"
To solve the problem, you could either statically type the receiver
when you call this method (with a type-casting for instance) or modify
your code in order for all the initWithCapacity: methods to have the
same signature (not sure, but something tells me that your
initWithCapacity: method is declared to take a "long" as parameter,
whereas the version declared in NSString.h takes an "unsigned").
Best,
Phil
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.