Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!spool.mu.edu!uunet!hsi!stpstn!lerman From: lerman@stpstn.UUCP (Ken Lerman) Newsgroups: comp.lang.objective-c Subject: Re: Inheritance question Message-ID: <6296@stpstn.UUCP> Date: 11 Feb 91 12:59:50 GMT References: <25258@grebyn.com> Reply-To: lerman@stpstn.UUCP (Ken Lerman) Distribution: comp.lang.objective-c Organization: The Stepstone Corporation, Sandy Hook, CT 06482 Lines: 61 In article <25258@grebyn.com> dougw@grebyn.com (Doug Worthington) writes: ... > > My problem is this. I want the user to get and set these >fields with the same routine names getValue and setValue without >having to cast the value as an char *, int etc. When the user >includes the interface files with the program the compiler is confused >with the names complaining that there are more then one get/setValues. >Which there are, one for each type of field with a different >return/parameter type. This lack of overloading is a bummer. I >realize I am a bit braindead on this problem but why can't the >compiler do some scoping of the arguements and determine which method >to call. > >Thanks > >Doug Worthington > >dougw@grebyn.com >localhost 12> If class Foo defines: -(char *)getValue; and class Bar defines: -(double)getValue; Then we can write: Foo *aFoo; Bar *aBar; aCharStar = [aFoo getValue]; aDouble = [aBar getValue]; and the compiler will disambiguate the two cases. NOTE that you MUST know the type of the receiver because the left hand size must be of the proper type. We could even write: id alpha, beta; aCharStar = [(Foo *)alpha aSelector]; aDouble = [(Bar *)beta aSelector]; The selection of which declaration of the selector to use is determined by the class of the receiver if the class can be determined. The user must (obviously) know which he was using because he had to assign to the proper type (char *, or double). The same is true if there are arguments of differing types as in: -setValue:(char *)arg; // in class Foo and -setValue:(double)arg; // in class Bar Ken