我不是白痴,但头文件有时让我觉得自己像个白痴.我有一个可能过于复杂的设置,它有一个我无法解决的错误.这是我能做到的尽可能简单的细节......
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....
当创建一个层并将控制器的模型传递给层的模型(在 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
#import <Foundation/Foundation.h>
@class Model;
@class AScene;
@interface Controller : NSObject {
Model *Model;
}
@property (nonatomic, retain) Model *Model;
-(void)runScene;
Controller.m
#import "Controller.h"
#import "Model.h"
#import "AScene.h"
@implementation Controller
@synthesize Model;
- (void)runScene {
AScene *newScene = [[AScene alloc] init];
newScene.controller = self;
}
RootScene.h
#import "cocos2d.h"
@class Controller;
@interface RootScene : Scene {
Controller *controller;
}
@property (nonatomic, retain) Controller *controller;
@end
RootScene.m
#import "RootScene.h"
#import "Controller.h"
@implementation RootScene
@synthesize controller;
- (id) init {
self = [super init];
if (self != nil) {
//
}
return self;
}
- (void) dealloc {
[controller release];
[super dealloc];
}
@end
AScene.h
#import "RootScene.h"
@class ALayer;
@class Model;
@interface AScene : RootScene {
}
@end
AScene.m
#import "AScene.h"
#import "ALayer.h"
#import "Model.h"
@implementation AScene
- (id) init {
self = [super init];
if (self != nil) {
ALayer *newLayer = [ALayer node];
newLayer.model = controller.Model; // <-- Request for member 'Model' in something not a stucture or union
[self addChild:statusScreenLayer];
}
return self;
}
- (void) dealloc {
[super dealloc];
}
@end
RootLayer.h
#import "cocos2d.h"
@class Model;
@interface RootLayer : Layer {
Model *model;
}
@property (nonatomic, retain) Model *model;
@end
RootLayer.m
#import "RootLayer.h"
#import "Model.h"
@implementation RootLayer
@synthesize model;
- (id) init {
self = [super init];
if (self != nil) {
//
}
return self;
}
- (void) dealloc {
[model release];
[super dealloc];
}
@end
ALayer.h
#import "RootLayer.h"
@interface ALayer : RootLayer {
}
-(void) draw;
@end
ALayer.m
#import "ALayer.h"
@implementation ALayer
-(void) draw {
// draw based on state of the model
}
@end
你的AScene
实现没有#import
Controller
的header.
Your implementation of AScene
does not #import
the header of Controller
.
显式解决方案.
在 AScene.m 中添加:
In AScene.m add:
#import "Controller.h"
这篇关于可能的循环引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!