gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

late binding when using id type -- newbie objc question


From: Martin Voelkel
Subject: late binding when using id type -- newbie objc question
Date: Mon, 23 Jun 2003 21:56:54 +0200

hello all,

i am porting a sound synthesis system originally written on a NeXTStep
system ten years ago and i am relatively new to GNUStep and objc (but
not to OO).

i encountered a general "problem" (much more a question) which isn't
there when compiling on an original NeXTStep-system regarding
late-binding when using the generic id type (rather than a static
type):

>>>>>

#include <Foundation/Foundation.h>

@interface TestClass : NSObject
{
}

- addObject: anObject;

@end


@implementation TestClass

- addObject: anObject
{
  // do nothing
 
  return self;
}

@end


int main (int argc, char **argv, char **env)
{
  id recv, ret;

  recv = [[TestClass alloc] init];

  ret = [recv addObject: [[NSObject alloc] init]];

  return 0;
}

<<<<<

when compiling, i get:

TestClass.m: In function `main':
TestClass.m:31: warning: multiple declarations for method `addObject:'
/usr/lib/GNUstep/System/Headers/Foundation/NSArray.h:106: warning: using 
`-(void)addObject:(id)anObject'
TestClass.m:15: warning: also found `-addObject:anObject'
TestClass.m:7: warning: also found `-addObject:anObject'
TestClass.m:31: error: void value not ignored as it ought to be
make[1]: *** [shared_obj/ix86/linux-gnu/gnu-gnu-gnu/TestClass.o] Error 1
make: *** [test.all.tool.variables] Error 2


this is because of the different return types of [NSArray addObject:]
and [TestClass addObject:] and the error in this case isn't the
question, but:

why does the compiler try to find out which selector in which class
could be meant by sending 'id' a message?  i ever thought that one of
the major advantages of objc is the late binding (at runtime) when
using the dynamic 'id' typing?  OTOH, the risk is deferred to runtime,
when the application may crash, but i tought that's the general
trade-off between early/late-binding.

so i wonder if i made a big mistake or misunderstood something
general.

thanks very much in advance for your help!

cheers,

martin

-- 
martin voelkel (address@hidden)
/* home is where your home directory is */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]