线程错误 - 线程1:Breakpoint1.1

时间:2012-10-26 07:32:16

标签: objective-c xcode

我附加了以下程序代码,用于显示分数的实际值,并且构建成功但程序因线程错误而崩溃。你能告诉我,我犯了什么错误。真的很感激帮助 由于
Maverick10

#import<Foundation/Foundation.h>

@interface Fraction : NSObject
{
    int numerator;
    int denominator; // variables to be used
}
-(void) print;
-(void) setNumerator:(int) n;
-(void) setDenominator:(int) d;
-(int) numerator;
-(int) denominator;
-(double) convertToNum; // new method declared
@end

@implementation Fraction
-(void) print
{
NSLog(@"%i/%i",numerator,denominator);
}
-(void) setNumerator :(int) n
{
numerator=n;
}
-(void) setDenominator :(int)d
{
denominator=d;
}
-(int)numerator
{
return numerator;
}
-(int) denominator
{
return denominator;
}
-(double) convertToNum
{
if(denominator!=0) // checking for denominator to be non zero
return (double) numerator/denominator;
else
return NAN;
}
@end
//Program Section
int main(int argc, char*argv[])
{
    NSAutoreleasePool * pool = [[ NSAutoreleasePool alloc] init];

    Fraction * aFraction =[[Fraction alloc] init];
    Fraction * bFraction =[[Fraction alloc] init];

    [aFraction setNumerator:1]; // setting the numerator for the first fraction.Similarly denominator
    [aFraction setDenominator:4];
    [aFraction print];
    NSLog(@"= ");
    NSLog(@"%g",[aFraction convertToNum]);

    [bFraction print];
          NSLog(@"="); 
    NSLog(@"%g",[bFraction convertToNum]);

    [aFraction release];
    [bFraction release];

    [pool drain];
    return 0;
}

1 个答案:

答案 0 :(得分:0)

你得到了Thread1:Breakpoint1.1,因为你在 - (void)setNumerator处添加了一个断点。你可能只是偶然点击了那个空格来添加断点。