警告:不兼容的 Objective-C 类型将超类分配给子类

发布于 2024-09-25 21:23:48 字数 189 浏览 0 评论 0原文

假设有一个有效的超类和一个有效的子类,即类可以工作。

子类的构造函数中的以下行 self = [超级初始化] ;

抛出以下警告 // 警告:不兼容的 Objective-C 类型分配“struct Animal *”,预期“struct Cat *”

关于如何修复此问题并删除警告有什么想法吗?

干杯

Assume a valid super class, and a valid subclass ie the classes work.

the following line in a constructor of the subclass
self = [super init] ;

throws the following warning
// warning: incompatible Objective-C types assigning 'struct Animal *', expected 'struct Cat *'

Any ideas on how to fix this and remove the warning ?

Cheers

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

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

发布评论

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

评论(1

清风夜微凉 2024-10-02 21:23:48

您是否在超类中提供自定义 init-Method ?

检查该方法的返回类型。是(动物*)吗?如果是这样,请将其更改为 (id)。

初始化方法应该返回(id)

Do you provide a custom init-Method in your superclass?

Check the return type of this method. Is it (Animal *)? If so, change this to (id).

Init methods should return (id)

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