[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
dynamic binding?
From: |
James Marshall |
Subject: |
dynamic binding? |
Date: |
Tue, 21 Jul 1998 14:27:23 GMT |
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? Maybe I've missed out a compiler flag,
but I'm including the standard (Swarm 1.1) Makefile.appl in my
makefile? There follows the complete source for the objects
concerned, and an example line of code that generates a compiler
warning for me...
James
//DoubleData.h Double wrapper for use with arrays
#import <objectbase.h>
@interface DoubleData: SwarmObject
{
double data;
}
-(double)getData;
-(void)setData: (double) newData;
@end
//DoubleData.m Double wrapper for use with arrays
#import "DoubleData.h"
@implementation DoubleData: SwarmObject
{
double data;
}
-(double)getData
{
return data;
}
-(void)setData: (double) newData;
{
data=newData;
}
@end
//IntegerData.h Integer wrapper for use with arrays
#import <objectbase.h>
@interface IntegerData: SwarmObject
{
int data;
}
-(int)getData;
-(void)setData: (int) newData;
@end
//IntegerData.m Integer wrapper for use with arrays
#import "IntegerData.h"
@implementation IntegerData: SwarmObject
{
int data;
}
-(int)getData
{
return data;
}
-(void)setData: (int) newData;
{
data=newData;
}
@end
[[alleles atOffset: l1] setData: [[alleles atOffset:
l1] getData]+(int)[[agent getStrategy] atOffset: l1]];
EPDWorld.m:154: warning: multiple declarations for method `getData'
IntegerData.h:10: warning: using `-(int)getData'
DoubleData.h:10: warning: also found `-(double)getData'
EPDWorld.m:154: warning: multiple declarations for method `setData:'
IntegerData.h:11: warning: using `-(void)setData:(int)newData'
DoubleData.h:11: warning: also found `-(void)setData:(double)newData'
--
James Marshall - Postgraduate Research Student (MPhil/PhD)
Artificial Intelligence Group - Department of Computer and Information Sciences
De Montfort University - Milton Keynes Campus
Web:- http://www.mk.dmu.ac.uk/~jmarshall/
==================================
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 <=