Obj-Cでコーディングする方法を学びたいと思っています。現在の目標は、矩形の面積と周囲長を計算する簡単なコマンドラインプログラムを書くことです。しかし、私がプログラムを試してみると、Xcodeは私にエラーを投げつけ続けます。私のコードで何が問題になっていますか? (Obj-C)
#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を押してブレークポイントウィンドウを見ると、そこから。 – filipe
これはブレークポイントではありません。あなたのプログラムはクラッシュしました。エラーメッセージを取得してここに貼り付けるには、デバッガーウィンドウを見てください。 – Codo