Class 类在哪里声明/如何转发声明?

发布于 2025-01-06 01:50:21 字数 589 浏览 4 评论 0原文

由于标头中存在此错误,我无法编译我的:

错误:预期标识符 [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 技术交流群。

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

发布评论

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

评论(1

带上头具痛哭 2025-01-13 01:50:21

我怀疑你的标题在 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 from class to some non-keyword.

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