Sorry, I accidentally posted my initial question (Doesn't one get a compiler warning about several methods being possible?) only to Stephen, not the list.


On 1 Oct, 2009, at 07:10, Stephen J. Butler wrote:

On Wed, Sep 30, 2009 at 10:16 PM, Colin Howarth <[email protected]> wrote:
Doesn't one get a compiler warning about several methods being possible?

I don't in 3.1.4 with this example. But now that you mention it, I do
seem to recall a warning along those lines. Although I don't know
quite how to trigger it.

#import <Cocoa/Cocoa.h>

@interface Foo : NSObject
{
}

+ (Foo*) foo;
- (float) mode;

@end

@implementation Foo

+ (Foo*) foo
{
        return [[[Foo alloc] init] autorelease];
}

- (float) mode
{
        return 1.0f;
}

@end


int main (int argc, const char * argv[]) {
   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSArray *array = [NSArray arrayWithObjects:[Foo foo], [Foo foo], [Foo
foo], nil];

        NSLog( @"foo0 = %f", [[array objectAtIndex:0] mode] );
        NSLog( @"foo0 = %f", [(Foo*)[array objectAtIndex:0] mode] );

   [pool drain];
   return 0;
}



Simple, replace

+ (Foo*) foo

with

+ (id) foo

in Foo.h and Foo.m


You then get the following warnings:

.../main.m: 19: warning: multiple methods named '-mode' found .../AppKit.framework/Headers/NSMatrix.h:123: warning: using '- (NSMatrixMode)mode' .../Foo.h: 16 : warning: also found '-(float)mode' .../AppKit.framework/Headers/NSColorPanel.h:97: warning: also found '-(NSColorPanelMode)mode'

The log then gives:

2009-10-01 15:05:30.110 bar[36703:a0f] foo0 = 0.000000
2009-10-01 15:05:30.118 bar[36703:a0f] foo0 = 1.000000



I like the way it picks one at random. I mean, "hey, as long as we can start the program..."
(I'm using 3.2 64-bit, btw)

--colin






_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to