[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dynamic binding?
From: |
Sven N. Thommesen |
Subject: |
Re: dynamic binding? |
Date: |
Tue, 21 Jul 1998 09:47:17 -0500 |
At 02:27 PM 7/21/1998 GMT, James Marshall wrote:
>Hi,
> I have a problem when compiling my Swarm app now, because I have
>two objects each with a method of the same name (but taking
>and returning different format parameters (ints or doubles). When I
>try to compile this the compiler warns of the multiple declarations
>and chooses one to use at compile time. Why does this happen? I
>though Objective C was supposed to allow polymorphism and dynamic
>binding? i.e. the method to use should be chosen at run-time, not
>compile time, after examination and determination of the type of the
>object receiving the message?
Well, yes, but that means different object classes are allowed to implement
the same method in different ways -- but 'the same method' means the
different implementations have to define the method interfaces in the exact
same way. I.e., you can have different classes implement '-(int)getData' in
different ways.
However, objectiveC keeps a single 'database' of method definitions, and it
is a limitation of the language that you are not allowed to have synonymous
methods returning different data types. So if you first define
'-(int)getData', you have an illegal duplicate when you define
'-(double)getData'. (It was probably too much work to build in the
necessary 'magic' to check at runtime for what size the return value is.)
Sorry 'bout that!
Cheers,
--Sven
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
==================================
- dynamic binding?, James Marshall, 1998/07/21
- Re: dynamic binding?,
Sven N. Thommesen <=