• 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
Function overloading for ObjC classes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Function overloading for ObjC classes


  • Subject: Function overloading for ObjC classes
  • From: Allan Odgaard <email@hidden>
  • Date: Sun, 22 Feb 2004 07:23:45 +0100

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"); }

Output:

In function `void foo(NSMutableData*)':
error: redefinition of `void foo(NSMutableData*)'
error: `void foo(NSData*)' previously defined here
error: redefinition of `void foo(NSMutableData*)'
error: `void foo(NSData*)' previously defined here

If I instead of importing Foundation.h then declare the classes like this:

@class NSData;
@class NSMutableData;

There are no compiler errors...

I wonder, is this a GCC bug? Overloading does work for "different" classes (i.e. non sub/super class relationships).
_______________________________________________
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: Phillip Hutchings <email@hidden>
    • Re: Function overloading for ObjC classes
      • From: Jens Bauer <email@hidden>
  • Prev by Date: Re: Manpage display in Cocoa
  • Next by Date: Re: Data Source object for NSTableView
  • Previous by thread: Re: Best Cocoa/Objective-C Book?
  • Next by thread: Re: Function overloading for ObjC classes
  • Index(es):
    • Date
    • Thread