• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Function overloading for ObjC classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Function overloading for ObjC classes
      • From: Ondra Cada <email@hidden>
    • Re: Function overloading for ObjC classes
      • From: Allan Odgaard <email@hidden>
References: 
 >Function overloading for ObjC classes (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Re: Data Source object for NSTableView
  • Next by Date: Re: Function overloading for ObjC classes
  • Previous by thread: Function overloading for ObjC classes
  • Next by thread: Re: Function overloading for ObjC classes
  • Index(es):
    • Date
    • Thread