Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 3, 2005, 10:53 PM   #1
Jordan72
macrumors member
 
Join Date: Nov 2005
Compiler Warnings: id and *id, multiple declarations

What syntax do I need so the XCode compiler accepts both id and id* types without giving me warnings? Although the compiler warnings don't turn into exceptions that stop my program in it's tracks or change my program logic, I heard it's good practice to remove all warnings and want to remove the warnings.

Code:
-method:(id)

-method:(id*)
I tried both versions by passing them both id and id* and my program worked fine, but how do I remove warnings with better syntax?


Since I'm on the topic of removing warnings, I can't seem to get rid of these kinds of warnings either.

I've only declared -(NSString *)set once:

Code:
[[sets objectAtIndex:i] omega:[[[sets objectAtIndex:i] set] length]-1];

warning: multiple declarations for method `set'

I never did declare -(int)length, so I don't know why it doesn't know what the heck is going on, since -(int)length is an NSString method.

Code:
[self possible:[self possible] * [[[sets objectAtIndex:i] set] length]];

warning: multiple declarations for method `length'
Jordan72 is offline   0 Reply With Quote
Old Dec 4, 2005, 04:19 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
You can't. A method in an ObjC class cannot be overloaded like it can in C++. You can't do what you are trying to do.

Why do you want to be able to pass id* anyway? id is already a pointer (it's declared as void* or obj_class* anyway).
robbieduncan is offline   0 Reply With Quote
Old Dec 4, 2005, 07:55 PM   #3
Jordan72
Thread Starter
macrumors member
 
Join Date: Nov 2005
I don't know what overloading is, but what I did describe up there worked fine, just got warnings.

Why id*? For the same reason of NSArray method:

Code:
- (id)initWithObjects:(id *)objects count:(unsigned)count
I'm merely following established conventions. We both want pointers to objects for our own purposes.

I did figure out the first part of the question. I just made my id an id*.

But I still don't know why I'm getting those others warnings, I bet it's something really simple.
Jordan72 is offline   0 Reply With Quote
Old Dec 4, 2005, 11:12 PM   #4
jeremy.king
macrumors 603
 
jeremy.king's Avatar
 
Join Date: Jul 2002
Location: Fox Lake, IL
Nevermind.
jeremy.king is offline   0 Reply With Quote
Old Dec 5, 2005, 03:44 AM   #5
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
- (id)initWithObjectsid *)objects countunsigned)count

Although it's possible to do stuff yourself like the above in objective-C it's much more common to send a group of objects in an array or a dictionary (depending upon your needs). Something like

[myObject myMethodWithArray:[NSArray arrayWithObjects: one, two, three, nil]];

Although my example is obviously more verbose and slower when you only ever use immutable objects I think the method is much more flexible if it can take any old array not just a list of objects. You also get to use the NSArray methods to access the elements rather than messing about with pointer arithmetic.
caveman_uk is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Application warnings harrybaker Mac Basics and Help 10 May 6, 2013 09:16 AM
USB warnings on wake up digitalfailure OS X 10.8 Mountain Lion 3 Apr 5, 2013 10:44 AM
Application warnings martymcgee OS X 10.8 Mountain Lion 0 Mar 26, 2013 04:00 PM
Another multiple ID, multiple device, multiple phone number iMessage question mrcalabash iOS 6 3 Jan 12, 2013 08:45 PM
iPad Mini: PLEASE! WAIT!~All these case warnings, here's why.... glen e iPad Accessories 27 Nov 8, 2012 11:00 AM

Forum Jump

All times are GMT -5. The time now is 02:37 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC