discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forcing the compiler to use a specific class/method


From: Nicola Pero
Subject: Re: Forcing the compiler to use a specific class/method
Date: Mon, 20 Jan 2003 16:34:55 +0000 (GMT)

> Hi all,
> 
> assume you  have the following two methods implemented:
> 
> UIConnection:
> ============
> + (void)connectionForPropertyList:(NSDictionary *)dic form:(UIForm 
> *)form;
> 
> WIConnection:
> ============
> + (void)connectionForPropertyList:(NSDictionary *)dic form:(WIForm 
> *)form;
> 
> The selector of both methods is identical, the signature and the 
> implementation is not. When I now do
> 
>       [WIConnection connectionForPropertyList:... form:...]
> 
> I get
> 
> WIForm.m:237: warning: multiple declarations for method 
> `connectionForPropertyList:form:'
> /home/ahoesch/Development/MacOSX/SmartObjects/FBDesign/UIConnection.h:45: 
> warning: using `+(void)connectionForPropertyList:(NSDictionary *)dic 
> form:(UIForm *)form'
> WIConnection.h:21: warning: also found 
> `+(void)connectionForPropertyList:(NSDictionary *)dic form:(WIForm 
> *)form'
> WIForm.m:237: warning: passing arg 2 of 
> `connectionForPropertyList:form:' from incompatible pointer type
> 
> It is using the wrong class. How can I force the compile to use 
> WIConnection?

Good question - there is no way to. :-)

This is - IMO - one of the very few limitations of the Objective-C
language which I'd often thought of fixing.

If you have an 'id', you can cast it to 'an instance of NSObject or of a
subclass of NSObject'.

But if you have a 'Class', you can not cast it to 'MyClass or a subclass
of MyClass'.

In practice, we have - 

 'id': a generic object
 'NSObject *': an object of class NSObject (or subclass) [this can be used
by the compiler to check that you only send to the object instance
messages which are implemented by its class]

 'Class': a generic class
 <missing syntax here>: a class object which is NSObject (or a subclass)
[this could be used by the compiler to check that you send to the class
only class messages which are implemented by the class].

Casting a 'Class' to 'MyClass or a subclass of MyClass' would be very
useful, because then the compiler could check the class messages that you
send to it, checking that 'MyClass or a subclass of MyClass' indeed
implements those class methods.  In special cases, if conflicting class
methods with conflicting signatures are available in different classes, it
would also help the compiler choose the right one (preventing a crash at
run time).

Unfortunately, ObjC has no syntax for that at the moment.

Any suggestion ?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]