开发者

virtual functions in Objective C

开发者 https://www.devze.com 2023-03-05 01:57 出处:网络
How to declare the virtual functions in Objective C. virtual vo开发者_Go百科id A(int s); How to declare the same 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
0

精彩评论

暂无评论...
验证码 换一张
取 消