gpt4 book ai didi

objective-c - 编译器无法识别我的自定义类

转载 作者:行者123 更新时间:2023-12-03 17:41:24 25 4
gpt4 key购买 nike

这是我的 Board 头文件:

#import "Game.h"
#import <Foundation/Foundation.h>

@interface Board : UIView
{
enum Piece;
}

- (void) setGame: (Game*) theGame; //<-- this is where the error is
typedef enum {X, O, NONE} Piece;
- (float)getSection;
@end

编译器显示“预期类型”并带有 (Game*) 下划线。这里有什么问题吗?

<小时/>

游戏.h:

#import <Foundation/Foundation.h>
#import "Board.h"

@interface Game : UIViewController

- (void)boardwasTapped:(int) row:(int) column;

@end

最佳答案

不要导入 header ,而是转发声明它。在 Board.m 中导入 Game 头

@class Game;

@interface Board : UIView {
...
}
...
@end

另外,您确定问题不是出在您的枚举上吗?在声明它之前,您在 header 中使用它。您应该在 @interface block 上方(外部)声明它。

关于objective-c - 编译器无法识别我的自定义类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13074416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com