A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© ixx__123 中级黑马   /  2014-8-21 22:40  /  1460 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

/*
设计一个方法,用来和其他车比较车速,返回车速的差距
*/
#import<Foundation/Foundation.h>
@interface Car :NSObject
{
   @public
   int= speed;
}
-(int)compareSpeedWihtOther:(Catr *)other;
@end
@imlemention Car
-(int)compareSpeedWihtOther:(Catr *)other
{
  //speed
  //other->speed
  //返回当前这辆车和other这辆车的速度差距
  return speed - other->speep;
}
@end
int main()
{
  Car *c1 =[Car new];
  c1->speed =300;
  
  Car *c2=[Car new];
  c2->speed =280;
  [c1 compareSpeedWithOther:c2];
  return 0;
]

4 个回复

倒序浏览
没弄明白你有什么问题
回复 使用道具 举报
  1. #import <Foundation/Foundation.h>
  2. @interface Car : NSObject
  3. {
  4.         @public
  5.         int speed;
  6. }
  7. - (int) compareSpeedWithOther : (Car *)other;
  8. @end

  9. @implementation Car
  10. - (int)compareSpeedWithOther :(Car *)other // Äãд´íÁË£¬ÊÇ(Car *)ÀàÐ굀 ²»ÊÇ (Catr *)
  11. {
  12.         return speed - other->speed;
  13. }

  14. @end

  15. int main()
  16. {
  17.         Car * c1 = [Car new];
  18.         c1->speed = 300;

  19.         Car * c2 = [Car new];
  20.         c2->speed = 280;

  21.         int chaju =[c1 compareSpeedWithOther : c2];
  22.         NSLog(@"the chaju is %d",chaju);
  23.         return 0;
  24. }
复制代码

以上是自己凭记忆写的,我没有编译器,也不知道到底正确不正确,楼主自己试试吧
回复 使用道具 举报
  1. -(int)compareSpeedWihtOther:(Catr *)other;
复制代码

这里的Car您误写成了Catr了,估计是这里的问题。
回复 使用道具 举报
return speed - other->speep;
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马