Re: subclass weirdness
Re: subclass weirdness
- Subject: Re: subclass weirdness
- From: Neil Earnshaw <email@hidden>
- Date: Mon, 30 Jun 2003 12:50:42 +0100
Here's a little project that replicates the problem you describe.
It creates a myBase and sends foo to it. MyBase responds.
It creates a mySub and sends foo to it. MyBase(super) responds, then
MySub responds.
It assigns mySub to MyBase* mySuper and sends foo to it. MyBase(super)
responds, then MySub responds. It behaves as you'd expect.
It declares MySub* myMistake but assigns a [[[MyBase alloc] init]
autorelease]; to it. Note the difference in the declared and assigned
types. The compiler doesn't issue a warning. When you send foo: to it
only MyBase responds because the thing you're pointing to is a MyBase,
not a MySub.
Alternatively, there's a signature mis-match in the definition of MySub
foo:.
Hope this helps,
Neil
[demime 0.98b removed an attachment of type application/x-stuffit which had a name of Archive.sit]
On Monday, June 30, 2003, at 03:35 AM, Koen van der Drift wrote:
>
Hi,
>
>
I thought by now I understand subclassing, but this is driving me
>
crazy ;)
>
>
Consider a base class and it's subclass: MyBase and MySub, both of
>
which have a method foo to which I pass an NSString:
>
>
-(void)foo:(NSString *)s
>
{
>
blahWithString...
>
}
>
>
>
and for MySub:
>
>
-(void)foo:(NSString *)s
>
{
>
[super foo:s];
>
>
moreBlahWithString...
>
}
>
>
>
When I call [mySub foo:aString], only the base class gets called, so
>
moreBlahWithString never gets executed. I stared at this too long now,
>
and I don't see what's wrong.
>
>
any ideas?
>
>
thanks,
>
>
- Koen.
>
_______________________________________________
>
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.
>
>
Neil Earnshaw
Consultant Software Engineer
Object Software Engineers Ltd
email@hidden
Tel : 01747 854 852
Mbl : 07870 209 102
_______________________________________________
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.