EXC_BAD 使用自己的结构作为返回值

发布于 2024-11-28 06:41:31 字数 378 浏览 2 评论 0原文

我使用以下结构作为方法的返回值:

typedef struct {
CLLocationCoordinate2D topLeftCorner;
CLLocationCoordinate2D bottomRightCorner;
} LCMapBoundings;

以下方法立即崩溃:

-(LCMapBoundings)calculate {
NSLog(@"test");
}

但是那个可以工作:

-(LCMapBoundings*)calculate {
NSLog(@"test");
}

为什么会这样?使用第一种方法时我搞砸了什么?

i am using the following struct as a return value of a method:

typedef struct {
CLLocationCoordinate2D topLeftCorner;
CLLocationCoordinate2D bottomRightCorner;
} LCMapBoundings;

The following method crashes instantly:

-(LCMapBoundings)calculate {
NSLog(@"test");
}

But that one works:

-(LCMapBoundings*)calculate {
NSLog(@"test");
}

Why is that? What am i messing up when using the first method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生一个溪 2024-12-05 06:41:32

也许它崩溃是因为您没有在方法中返回值?这是未定义的行为。

Perhaps it's crashing because you don't return a value in your method? That's undefined behaviour.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文