尽管导入了正确的标头,但使用自定义类时出现编译器错误

发布于 2024-12-17 11:30:59 字数 382 浏览 2 评论 0原文

在我的 iOS 应用程序中,我有一个带有参数类型的接口,这些参数类型是我创建的继承自 NSObject 的类。 示例:

- (void) addTarget:(Target *)target;

在此接口中,我有 #include "Target.h",在该文件中定义了 Target 的接口。但是,每当我使用如上所述构建的任何类时,我都会遇到以下编译器错误:

“目标”之前应有“)”

但是,当我将参数的类型更改为内置类型时,它工作得很好。这是我在 Objective C 中的第一个项目。我是否缺少一些基本的东西?

In my iOS app, I have an interface with parameter types which are classes I've created that inherit from NSObject.
Example:

- (void) addTarget:(Target *)target;

In this interface, I have #include "Target.h", in which file the interface for Target is defined. However, whenever I use any classes I've built as above, I end up with this compiler error:

Expected ')' before 'Target'

However, when I change the type of the parameter to a built-in type, it works just fine. This is my first project in Objective C. Is there something fundamental I'm missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

送舟行 2024-12-24 11:30:59

是的,您需要#import "Target.h",或者声明您的自定义类的任何头文件。否则,编译器将不知道您在说什么。

Yes, you need to #import "Target.h", or whatever header file your custom classes are declared in. Otherwise, the compiler will have no idea what you're talking about.

心舞飞扬 2024-12-24 11:30:59

正如评论中提到的,删除循环依赖关系解决了问题。

As mentioned in the comments, removing the cyclic dependencies fixed the problem.

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