【发布时间】:2018-01-21 01:59:38
【问题描述】:
尝试在 Objective-C++ 中调用函数时,我收到错误 Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
这是我要运行的代码:
int main(int argc, char* argv[])
{
[WindowController init]; //Fatal error on this line
return 0;
}
和
#include "Cocoa/Cocoa.h"
@interface WindowController : NSObject
{
@private
NSWindow* Window;
}
-(id)init;
-(void)close;
@end
@implementation WindowController
-(id)init
{
id obj = [super init];
if (obj)
{
NSRect WindowRect = NSMakeRect(100, 100, 100, 100);
Window = [[NSWindow alloc] initWithContentRect:WindowRect styleMask:NSWindowStyleMaskTitled|NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable|NSWindowStyleMaskClosable backing:NSBackingStoreBuffered defer:NO];
[Window setTitle:@"New Window"];
[Window setReleasedWhenClosed:NO];
[Window setMinSize:NSMakeSize(50, 50)];
NSView* View = [Window contentView];
[View setAutoresizesSubviews:YES];
[View setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
}
return self;
}
-(void)close
{
[Window close];
[Window dealloc];
[super dealloc];
}
@end
【问题讨论】:
标签: objective-c cocoa objective-c-runtime