Created by 大刘 liuxing8807@126.com
Java/c++/c#/swift全部支持方法重载, 但OC不支持重载,可以利用编译器使用C方法重载
//
// ViewController.m
// C_overload
//
// Created by liuweizhen on 2018/12/14.
// Copyright © 2018 daliu. All rights reserved.
//
#import "ViewController.h"
__attribute__((overloadable)) double sum(double a, double b) {
return a + b;
}
__attribute__((overloadable)) int sum(int a, int b) {
return a + b;
}
__attribute__((overloadable)) int sum(UIView *a, UIView *b) {
return 100;
}
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%d", sum(self.view, self.view));
}
@end
网友评论