0

Possible Duplicate:
Method overloading in Objective-C?

Is method overloading not possible. I have two functions with the same name. When declared like the below i'm etting errors.

-(RS232Msg*)CreateMessage:(REMOTE_MESSAGE_ID) nMessageNumber;
-(RS232Msg*)CreateMessage:(const uint8_t*) szMessageName;

when declared -(RS232Msg*)CreateMessage:(const uint8_t*) szMessageName; i'm not getting any errors. I also have two functions as the same name with different return type and argument.But its working fine and there is no error in its declaration. Why is it so?

Community
  • 1
  • 1
spandana
  • 755
  • 1
  • 13
  • 29

1 Answers1

3

No, method overloading is not possible in C, and therefore not possible in Objective-C (since Objective-C is a superset of C). If you'd like to use those two methods, you'll have to change their names. I would suggest the following:

- (RS232Msg *)createMessageWithMessageID:(REMOTE_MESSAGE_ID)nMessageNumber;
- (RS232Msg *)createMessageWithName:(const uint8_t*)szMessageName;
Itai Ferber
  • 28,308
  • 5
  • 77
  • 83