本帖最后由 傘が咲く 于 2014-5-8 00:00 编辑
写了一个车类,编译有警告,这是为啥!
Car2.m:27:1: warning: control may reach end of non-void function [-Wreturn-type] }
- #import <Foundation/Foundation.h>
- //定义Car类
- @interface Car2 : NSObject
- {
- @public
- char *name;
- int speed;
- }
- //用于与其他车对象比较速度
- - (int)compareSpeedWithOthers:(Car2 *)car;
- @end
- @implementation Car2
- - (int)compareSpeedWithOthers:(Car2 *)car
- {
- if(speed > car->speed)
- return 1;
- if(speed == car->speed)
- return 0;
- if(speed < car->speed)
- return -1;
- }
- @end
- int main()
- {
- Car2 *c1 = [Car2 new];
- Car2 *c2 = [Car2 new];
- c1->name = "BMW";
- c1->speed = 200;
- c2->name = "TANK";
- c2->speed = 300;
- int result = [c1 compareSpeedWithOthers:c2];
- NSLog(@"%d",result);
- return 0;
- }
复制代码
|