【发布时间】:2011-07-20 12:57:31
【问题描述】:
所以我现在正在尝试学习如何在 Obj-C 中编码,我目前的目标是编写一个简单的命令行程序来计算矩形的面积和周长;但是,当我尝试该程序时,Xcode 不断向我抛出错误。 这是我的代码:
#import <Foundation/Foundation.h>
@interface Rectangle : NSObject {
@private
int width;
int height;
}
-(void) setWidth: (int) w;
-(void) setHeight: (int) h;
-(int) width;
-(int) height;
-(int) area;
-(int) perimeter;
@end
@implementation Rectangle
-(void) setWidth:(int)w
{
width = w;
}
-(void) setHeight:(int)h
{
height = h;
}
-(int) width
{
return width;
}
-(int) height
{
return height;
}
-(int) area
在这一行我收到错误“线程 1:在断点 1 处停止”
{
return height*width;
}
-(int) perimeter
{
return 2 * width + 2 * height;
}
@end
int main (int argc, const char * argv []){
@autoreleasepool {
Rectangle * shape1 = [Rectangle new];
[shape1 setHeight: 5];
[shape1 setWidth: 15];
NSLog(@"the area of the rectangle is %i and the perimeter is %i", [shape1 area], [shape1 perimeter]);
}
return 0;
}
【问题讨论】:
-
您应该复制从编译器/gdb 获得的整个错误消息并将其粘贴到此处。
-
我遇到过几次这个问题,xcode 在一些我在代码编辑器中看不到的“幽灵”断点处中断,但如果你点击 cmd+alt+B 并查看断点窗口,您可以从那里禁用或删除它们。
-
这不是断点。你的程序崩溃了。查看调试器窗口以获取错误消息并将其粘贴到此处。
标签: objective-c macos xcode4 area