Re: Function overloading for ObjC classes
Re: Function overloading for ObjC classes
- Subject: Re: Function overloading for ObjC classes
- From: Jens Bauer <email@hidden>
- Date: Sun, 22 Feb 2004 08:00:32 +0100
Hi Allan,
On Sunday, Feb 22, 2004, at 07:23 Europe/Copenhagen, Allan Odgaard
wrote:
I wanted to write two versions of a function, one for NSData and
another for NSMutableData. Unfortunately the compiler says that I
redefine the same function. Example:
#import <Foundation/Foundation.h>
void foo (NSData* data) { printf("Data\n"); }
void foo (NSMutableData* data) { printf("Mutable Data\n"); }
You can't do that.
ObjC isn't like C++. It's more like an extension of C. It does not
support function overriding.
However, you could have two different functions in each their own
files, which are only accessed from within these files, by prefixing a
'static' keyword in front of the functions, but that's probably not
what you want.
I think you would either have to...
A: Provide two different function names
...or...
B: Make one function, that checks if it's a NSData * or a NSMutableData
class.
...Most likely, you'd prefer the latter.
Love,
Jens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.