Class 类在哪里声明/如何转发声明?
由于标头中存在此错误,我无法编译我的:
错误:预期标识符 [1]
-(void)removeAllEntitiesOfClass:(Class)class;
插入符号指向小写类。
删除这个函数会再次编译。
我的类是 NSObject 的子类,它具有使用 Class 的公共方法,所以我认为这会自动声明。
我还尝试将 Class 更改为 Class* 并使用 @Class Class 进行前向声明,但这不起作用 - 它说这是重新定义,因为我正在更改类型。显然 Class 是一个类型定义的结构指针。我不知道如何在这里转发声明,而且我似乎记得转发声明指针 typedef 可能是一件令人讨厌的事情。如果我错了,请纠正我,并告诉我要导入什么文件或如何转发声明。
@interface GameState : NSObject {
...
}
...
-(void) removeAllEntitiesOfClass:(Class)class;
@end
I cannot compile my because of this error in my header:
error: expected identifier [1]
-(void) removeAllEntitiesOfClass:(Class)class;
with the caret pointing to the lowercase class.
Removing this function makes it compile again.
My class is a subclass of NSObject, which has public methods that use Class, so I thought this would automagically be declared.
I also tried changing Class to Class* and forward declaring with @Class Class, and this doesn't work - it says it is a redefinition because I am changing the type. Apparently Class is a typedef'd struct pointer. I'm not sure how to forward declare that here, and I seem to recall it can be nasty business to forward declare a pointer typedef. Please correct me if I'm wrong, and tell me what file to import or how to forward declare.
@interface GameState : NSObject {
...
}
...
-(void) removeAllEntitiesOfClass:(Class)class;
@end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑你的标题在 Objective-C++ 翻译中是可见的。在 C++ 中,
class
是一个关键字。要解决此问题,请将参数名称从class
更改为某个非关键字。I suspect your header is visible in an Objective-C++ translation. In C++,
class
is a keyword. To fix this, change the parameter's name fromclass
to some non-keyword.