剛剛開始在Objective C中編程...指向接口對象的指針給出了分段錯誤
這段代碼給了我一個段錯誤。它出什麼問題了? 我知道它確實與「指令」有關。該陣列工作正常。
Instruction.h:
#ifndef romo_objectice_c_Instruction_h
#define romo_objectice_c_Instruction_h
#endif
#import <Foundation/Foundation.h>
typedef enum direction {north, south, west, east} Direction;
@interface Instruction:NSObject
@property Direction dir;
@property unsigned int distance;
@end
ViewController.m:
#import "Instruction.h"
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize instructionList;
- (void)viewDidLoad {
[super viewDidLoad];
instructionList = [[NSMutableArray alloc] init];
//THE FOLLOWING CODE CAUSES THE SEGMENTATION FAULT
Instruction *i;
Direction d = north;
i.distance = 1;
i.dir = d;
[instructionList queuePush:i];
}
任何想法? 謝謝。
瞭解如何獲取異常堆棧跟蹤,以確定故障點。 – 2015-04-05 19:46:33