在类方法中调用父类给了我“匹配方法签名”警告

发布于 2024-11-17 16:08:28 字数 582 浏览 1 评论 0原文

我有一个类,其中添加了两个类 A 和 B。在 A 类的方法中,我尝试调用 B 类方法

假设父类是 debugZoneScene,debugZoneLayer 是 A 类,tetraCounter 是 B 类。

这是 debugZoneLayer(A 类)中的一个方法:

-(void) getHeroVel {
    DebugZoneScene *debugZoneScene = (DebugZoneScene*)self.parent;

    [debugZoneScene.tetraCounter setTetras]; 
}

它调用该方法,但我收到警告:

'-[DebugZoneLayer getHeroVel]': “CCNode”可能不会响应“-setTetras”(没有匹配方法签名的消息将被假定返回“id”并接受“...”作为参数。)

我尝试过谷歌搜索这个,但我真的找不到任何与我的问题完全相关的东西。我正在使用 Cocos2D,但我认为这个问题与此没有任何直接关系,并且仍然可以通过 Objective C 知识来解决。有什么想法吗?

I have a class that has two classes A and B added to it. In a method in class A, I am trying to call a class B method

Let's assume that the parent class is debugZoneScene, debugZoneLayer is class A and tetraCounter is class B.

Here is a method from debugZoneLayer (class A):

-(void) getHeroVel {
    DebugZoneScene *debugZoneScene = (DebugZoneScene*)self.parent;

    [debugZoneScene.tetraCounter setTetras]; 
}

It calls the method, but I get the warning:

'-[DebugZoneLayer getHeroVel]':
'CCNode' may not respond to '-setTetras' (Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments.)

I've tried Googling this, but I couldn't really find anything that related exactly to my problem. I am using Cocos2D, but I think this problem doesn't have anything to do directly with that, and can still be resolved having knowledge in Objective C. Any ideas?

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

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

发布评论

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

评论(2

鼻尖触碰 2024-11-24 16:08:28

编译器告诉您,它认为 debugZoneScene.tetraCounterCCNode 类型的对象,而不是您的 ClassB 类型的对象。检查tetraCounter是如何在DebugZoneScene中声明和分配的。

您可以通过强制转换使警告消失:

[(ClassB *)(debugZoneScene.tetraCounter) setTetras]; 

这告诉编译器您不关心它的想法,并且您确定该对象是ClassB。然而,这并不能解决实际问题。

The compiler is telling you that it thinks that debugZoneScene.tetraCounter is an object of type CCNode, not whatever your ClassB is. Check how tetraCounter is declared and allocated in DebugZoneScene.

You can make the warning go away by casting:

[(ClassB *)(debugZoneScene.tetraCounter) setTetras]; 

this tells the compiler that you don't care what it thinks and you're sure that the object is ClassB. This doesn't solve the actual problem, however.

╭⌒浅淡时光〆 2024-11-24 16:08:28

您的伪代码确实适合您...如果没有有关 setTetras 签名的更多详细信息,将很难猜测您的代码中出了什么问题 ^^

无论如何,您是否 #import TatraCounter 类声明的标头,以便您所在的文件编写此代码知道 TetraCounter 对象的可用方法(及其签名)吗?

Your pseudo really fits you... without more details about the signature of setTetras, it will be quite difficult to guess what is wrong in your code ^^

Anyway did you #import the header for TatraCounter class declaration, so that the file where you wrote this code knows about the methods available (and their signature) for the TetraCounter objects?

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