home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!news.dell.com!uudell!pensoft!usenet
- From: kari@pencom.com (Kari Karhi)
- Newsgroups: comp.sys.next.programmer
- Subject: Re: Multiple init: functions defined
- Keywords: Objective-C,variable declaration
- Message-ID: <1992Sep3.134909.9180@pencom.com>
- Date: 3 Sep 92 13:49:09 GMT
- References: <Btz6sL.8qC@oceania.com>
- Sender: usenet@pencom.com (Usenet Psuedo User)
- Reply-To: kari@pencom.com
- Organization: Pencom Software
- Lines: 72
-
- In article <Btz6sL.8qC@oceania.com> jim (Jim Mackraz) writes:
- > Jack Gidding writes
- > >
- > > Hmmmm..... this is really strange and very undesired behavior from
- > Objective-C.
- > >
- > > When I include the header files from two different classes into a third
- > class,
- > > and each of the included classes have a single init: method defined, I get
- > > messages similar to the following:
- > >
- > >
- > > main2.m:18: warning: multiple declarations for method `init:'
- > > /Clib/RP.h:32: using `-init:(int )pSize'
- > > /Clib/RS.h:31: also found `-init:(OBJPTR )s'
- > >
- > >
- > > Why is this happening??? Sometimes it tells me that it resolved which init
- to
- > > use, sometimes not, and sometimes it resolves it to the wrong init:.
- > >
- > >
- > > The code that has the init method is sililar in form to:
- > >
- > > #import <RP.h> // Both RP and RS have and init: method
- > > #import <RS.h>
- > >
- > > id x;
- > >
- > > x = [[RP alloc] init:(int) 5];
- > >
- > > id is totally dynamic, and thus it really does not know which init to
- use....
- > >
- > > So, why is it telling me that it is using one method or another...shouldn't
- > > this be left up until run-time?
- > >
- > >
- > > Am I doing something wrong to cause this?
- >
- > Yeah, you're "type overloading" the method "init:". Don't do that.
- > Make one of the "-initInt: (int) intVal" and the other one
- > "-initObj: (OBJPTR) obj"
- >
- > .... or something like that.
- >
- >
- > > Thanks,
- > >
- > >
- > > Jack Gidding
- > > jack@richsun.cpg.trs.reuter.com
- > --
- > Jim Mackraz
- > jim@oceania.com
-
- Another way is to declare the variable x as
- RP *x;
- This gives enough clues to the compiler to avoid the warning messages and you
- are, after all, initializing an instance of class RP. If x can also be
- something else, then you can not use this way. You can also try making the two
- init methods have identical declarations, ie. same argument names and types and
- same return types. Then the compiler will not see any differences and will be
- happy. In your case that may not be possible either. In that case renaming
- the method name may be the only solution (outside of just living with the
- warning messages).
-
- Cheers,
- Kari Karhi
- Pencom Software
- (512)343-1111
- kari@pencom.com
-