Article View: comp.lang.objective-c
Article #291Re: problem with similar instance method names
From: tuncay
Date: Mon, 21 Dec 1992 20:44
Date: Mon, 21 Dec 1992 20:44
63 lines
2917 bytes
2917 bytes
hi,
In article <1992Dec18.183133.6855@ennews.eas.asu.edu>,
raothall@iienext1.cim.eas.asu.edu (Karthic V. Rao-Thallikar) says:
>
I ran into the same problem with compiling the same program on the NeXT
platform. My advisor solved the problem by:first including the header files of
the classes istead of .m files, then, compiling the .m files all together.
cc -ObjC Integer.m Float.m Fraction.m theMain.m
rm
>To all Objective-C Guru's:
>I am starting to write code in ObjecC. I am familiar with 'C'.
>My understanding of OOP is that if there are two similar classes eg
>Integer and Float the user can have the facility of using similarly named
>instance methods to operate on these classes. Just to try this out i coded
>the following lines. But the compiler reports errors for the 'initialize'
>and 'incrementBy' methods, and used the method defined for the Integer
>Class.
>Please do reply the correct procedure.
>I am using NeXt 3.0, and NeXt's ObjectiveC version that comes with the 3.0
>version.
>Thank you all in advance.
>Following is the code.
>They are in different file but I have 'cat' them for convinience.
>The error from the compiler is appended at the end for reference.
>
>//Test program for late bindind
>#import "Integer.m"
>#import "Float.m"
Here, import the header files: Integer.h, Float.h and Fraction.h
>#import "Fraction.m"
>#import <stdio.h>
>
>errors are:
>> cc test.m
you have to use -ObjC option when you compile Objective C code in the NeXT
platform, as far as I know. Use the following command:
cc -ObjC Integer.m Float.m Fraction.m test.m -o test
>Float.m: In method `new:'
>In file included from test.m:4:
>Float.m:8: warning: multiple declarations for method `initialize:'
>Integer.h:11: using `-initialize:(int)anInt'
>Float.h:10: also found `-initialize:(float)aValue'
>Float.m: In method `incrementBy:'
>Float.m:20: conflicting types for `-incrementBy:(float)aValue'
>Float.h:12: previous declaration of `-incrementBy:(int)aValue'
>test.m: In function `main':
>test.m:46: warning: multiple declarations for method `incrementBy:'
>Integer.h:13: using `-incrementBy:(int)aValue'
>Float.m:20: also found `-incrementBy:(float)aValue'
>>
The above two changes should fix the problem. I like PINSON/WIENER'S book
a lot despite the fact that I could not work some of their code on
the machine that I use. It is a NeXT, too.
Have fun.
Technical Details
Message-ID:
<92356.154409TOZNAL@MIAMIU.BITNET>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!ohstpy!miavx1!miamiu!toznalReferences:
<1992Dec18.183133.6855@ennews.eas.asu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!ohstpy!miavx1!miamiu!toznal Newsgroups: comp.lang.objective-c Subject: Re: problem with similar instance method names Message-ID: <92356.154409TOZNAL@MIAMIU.BITNET> From: tuncay <TOZNAL@MIAMIU.BITNET> Date: Monday, 21 Dec 1992 15:44:09 EST References: <1992Dec18.183133.6855@ennews.eas.asu.edu> Distribution: comp.lang.objective-c Organization: Miami University - Academic Computer Service Lines: 63