Can someone explain “Dereference of a null pointer” warning

﹥>﹥吖頭↗ 提交于 2020-01-25 10:01:09

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/4997165/can-someone-explain-dereference-of-a-null-pointer-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!