Re: Inheritance question
Re: Inheritance question
- Subject: Re: Inheritance question
- From: Chris Suter <email@hidden>
- Date: Fri, 17 Aug 2007 21:16:13 +1000
On 17/08/2007, at 9:02 PM, Tony Wroblewski wrote:
It doesn't work because you are still sending the message to your
object, even if you cast it. It doesn't work the same as C++, when
you can do virtual methods.
Just to add to this, objective C resolves method calls at run-time.
Wouldn't [[[myClassInstance] super] theMethod] work, although its
incredibly ugly
No, it won't.
The only way I can think of doing it would be to call
objc_msgSendSuper directly.
For example, this appears to work:
#include <Foundation/Foundation.h>
#include <objc/objc-runtime.h>
@interface ObjectA : NSObject {
}
@end
@implementation ObjectA
- (void)myMethod
{
NSLog (@"ObjectA");
}
@end
@interface ObjectB : ObjectA {
}
@end
@implementation ObjectB
- (void)myMethod
{
NSLog (@"ObjectB");
}
@end
int main ()
{
ObjectB *b = [[ObjectB alloc] init];
struct objc_super s = { b, [ObjectA class] };
objc_msgSendSuper (&s, @selector (myMethod));
return 0;
}
Having said that, I can't think of any good reason why you'd want to
do this. If you want to expose functionality in a super class write
another method.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden