黑马程序员技术交流社区

标题: 关于类的设计报错问题 [打印本页]

作者: 那个Mr_Z    时间: 2014-4-17 11:39
标题: 关于类的设计报错问题
#import <Foundation/Foundation.h>

typedef enum{
    SexMan,
    SexWomen

  }Sex;

  typedef struct
  {
     int year;

     int month;
     int day;
  }Date;

@interface Student:NSObject
{       @public
        Sex sex;
        double weight;
        Date birthday;
        char *name;

}
-(void)eat;
-(void)run;

@end
@implementation Student
-(void)eat
{
    weight +=1;
    NSLog(@"现在是%d斤",weight);

}
-(void)run
{
    weight -=1;
    NSLog(@"现在是%d斤",weight);

}
@end
int main()
{
        Student *p = [Student new];
        p->weight=50;
        p ->sex =SexMan;
        p->birthday.year =2011;
        p->birthday.month = 12;
        p ->birthday.day = 16;
        [p run];
        [p eat];
        return 0;

}
报错原因:Codeponit out of the rage of the constant string
我想问下,我是在Codeblock里编译的,这个错误是什么意思?
作者: 脸皮猴    时间: 2014-4-17 12:48
  1. @implementation Student
  2. -(void)eat
  3. {
  4.     weight +=1;
  5.     NSLog(@"现在是%d斤",weight);

  6. }
  7. -(void)run
  8. {
  9.     weight -=1;
  10.     NSLog(@"现在是%d斤",weight); // %d改为%f看看,别的找不到有错误的了。我在xcode上没问题

  11. }
复制代码


作者: D调的沉默    时间: 2014-4-17 13:41
我也没看出来什么问题。。。
作者: conpgy    时间: 2014-4-17 14:46
本帖最后由 conpgy 于 2014-4-17 14:55 编辑

除了上面提示的改为%f外。这里错误提示的意思大概意思是编码格式超出字符串的范围。就是NSLog里面不支持中文。这段代码是没有错的,Xcode是没有问题的。那就是window环境或者是编译器对中文格式的问题了。




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2