问题描述
我不是白痴,但头文件有时让我觉得自己像个白痴.我有一个可能过于复杂的设置,它有一个我无法解决的错误.这是我能做到的尽可能简单的细节......
I am not an idiot, but header files make me feel like one sometimes. I have what is probably an overly-complicated set-up that has an error that I cannot resolve. Here it is in about as simple as detail as I can make it....
- 我有一个包含模型类的控制器类.
- 我有一个 Scene 类来捕捉动作并与控制器通信.
- 我有一个 Layer 类,它与 Model 类对话以输出 Model 的状态.
- Scene 类包含仅用于输出的 Layer 类.
- 场景必须包含 Cocos2D 框架确定的层.
- 特定场景类派生自 RootScene 类,该类包含对 Controller 类的引用.
- 特定的 Layer 类派生自 RootLayer 类,该类包含对 Model 类的引用.
- 控制器负责创建场景,场景负责创建层.
当创建一个层并将控制器的模型传递给层的模型(在 AScene.m
中)时,问题就出现了.我收到在非结构或联合的情况下请求成员‘模型’".铸造不起作用,我不知道如何让这些类相互交谈.我认为部分问题可能是 Controller 类包含 Model 类.
The problem comes when making a Layer and passing the Controller's Model to the Layer's Model (in AScene.m
). I get the "Request for member 'Model' in something not a stucture or union". Casting doesn't work, and I'm at a loss for how to allow these classes to talk with each other. I think part of the problem might be that Controller class contains the Model class.
Controller.h
Controller.m
RootScene.h
RootScene.m
AScene.h
AScene.m
RootLayer.h
RootLayer.m
ALayer.h
ALayer.m
推荐答案
你的AScene
实现没有#import
Controller
的header.
Your implementation of AScene
does not #import
the header of Controller
.
显式解决方案.
在 AScene.m 中添加:
In AScene.m add:
这篇关于可能的循环引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!