有人可以解释一下“空指针的取消引用”吗?警告
我已经编写了几个可以工作并且看起来没有错误的应用程序(即,它们不会崩溃...),但我收到了以下代码的警告(我使用了几次) -
在@界面 -
GameViewController *controller;
在@implementation -
-(id)initWithOwner:(GameViewController *)aController withName:(NSString *)manName {
if (self = [super init]) {
// do stuff
}
controller = aController;
在最后一行,它说“取消引用空指针”。我对 Objective-C(以及 C)相当陌生,所以我不知道它意味着什么。任何帮助&解释赞赏!
I've written a couple of apps which work and seem bug free (ie, they don't crash...) but I get warnings for the code below (which I use a few times) -
In the @interface -
GameViewController *controller;
In the @implementation -
-(id)initWithOwner:(GameViewController *)aController withName:(NSString *)manName {
if (self = [super init]) {
// do stuff
}
controller = aController;
On that last line, it says "Dereference of a null pointer". I'm fairly new to Objective-C (and C as well) so I haven't a clue what it means. Any help & explanation appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,各位 - 经过更多研究后,我发现了这个问题。显然(至少现在很明显!) self 最终可能会为零 - 请参阅这篇文章: Dereference of Null Pointer
Sorry folks - I've found out the problem, after a bit more research. Obviously (at least it's obvious now!) self could end up as nil - see this post: Dereference of Null Pointer