virtual functions in Objective C
How to declare the virtual functions in Objective C.
virtual vo开发者_Go百科id A(int s);
How to declare the same in Objective C.
-(void)A:(int)s //normal declaration
Objective-c does not support virtual functions, or to say that another way - all functions in obj-c classes are virtual as method calls are determined in run-time.
If your subclass overrides method from superclass and you reference subclass instance using pointer to superclass then subclass method will get called:
@interface A{
}
-(void) someMethod;
@end
@interface B : A{
}
-(void) someMethod;
@end
...
A* obj = [[B alloc] init];
[obj someMethod]; // method implementation from B will be called
精彩评论