错误:“类名”重新声明为不同类型的符号?

发布于 2024-12-03 10:21:17 字数 1021 浏览 0 评论 0原文

我遇到了与此 问题

我通过在 .h 文件中使用 class 参数 提前声明类的解决方案克服了这个错误,

我有 FFTBufferManager.h 和FFTBufferManager.cpp 文件并在 HomeView.h 和 HomeView.mm 文件中使用它

class FFTBufferManager,CAStreamBasicDescription,DCRejectionFilter;

但现在我遇到错误

#include "FFTBufferManager.h"
#include "aurio_helper.h"
#include "CAStreamBasicDescription.h"

class CAStreamBasicDescription,FFTBufferManager;  //here it shows this error
   EXpected Unqualified-id befor ',' token


@interface HomeView 
{
    FFTBufferManager*           fftBufferManager;
//it shows erros 
 EXpected Unqualified-id befor ',' token
    ISO c++ forbids declaration of FFTBufferManager with no type

}

    @property FFTBufferManager*     fftBufferManager;
 //shows error
'FFTBufferManager' is not a type

I was facing the same error as asked in this question

I overcome with this error by solution of declaring class ahead of time in my .h file with the class parameter

I am having FFTBufferManager.h and FFTBufferManager.cpp file and using it in HomeView.h and HomeView.mm file

class FFTBufferManager,CAStreamBasicDescription,DCRejectionFilter;

But now I am having error as

#include "FFTBufferManager.h"
#include "aurio_helper.h"
#include "CAStreamBasicDescription.h"

class CAStreamBasicDescription,FFTBufferManager;  //here it shows this error
   EXpected Unqualified-id befor ',' token


@interface HomeView 
{
    FFTBufferManager*           fftBufferManager;
//it shows erros 
 EXpected Unqualified-id befor ',' token
    ISO c++ forbids declaration of FFTBufferManager with no type

}

    @property FFTBufferManager*     fftBufferManager;
 //shows error
'FFTBufferManager' is not a type

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

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

发布评论

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

评论(3

-残月青衣踏尘吟 2024-12-10 10:21:17

我猜你同时使用 C++ 和 Objective-C。

我建议重命名所有包含 Objective-C 和 C++ 代码的 .cpp.m 文件,以使用扩展名 .mm - 这告诉编译器使用“Objective-C++”规则,并且会阻止很多编译器麻烦。

另外,CAStreamBasicDescriptpion 似乎是一个 C++ 类 - 您必须使用 class CAStreamBasicDescriptpion; 来转发声明它,而不是 @ class CAStreamBasicDescriptpion;(注意,没有“at”符号)- 第二种形式仅适用于前向声明 Objective-C 类。我怀疑这是您观察到的特定错误的根本原因。

编辑回应评论:我不确定您的第一个新问题 - 只要 FFTBufferManagerCAStreamBasicDescription 都可以正常工作C++ 类。至于你的第二个,根据该行代码的具体位置(CAStreamBasicDescription thruFormat;),你可能需要包含标头而不仅仅是前向声明:你正在声明 < 的实例code>CAStreamBasicDescription 在这里,编译器需要知道它的结构才能这样做。

I'm gathering you're using both C++ and Objective-C.

I'd suggest renaming all your .cpp and .m files in which Objective-C and C++ code are meeting to use the extension .mm - this tells the compiler to use "Objective-C++" rules, and will stop a lot of compiler troubles.

Also, it seems CAStreamBasicDescritpion is a C++ class - you'll have to forward-declare it with class CAStreamBasicDescritpion;, not @class CAStreamBasicDescritpion; (note, no "at" sign) - the second form is only for forward-declaring Objective-C classes. This I suspect is the root cause of the particular error you have observed.

EDIT in response to comment: I'm not sure about your first new issue - that should work fine so long as both FFTBufferManager and CAStreamBasicDescription are C++ classes. As to your second one, depending on where exactly that line of code is (CAStreamBasicDescription thruFormat;) you may need to include the header rather than just the forward-declare: you're declaring an instance of CAStreamBasicDescription here, and the compiler needs to know its structure to do so.

肥爪爪 2024-12-10 10:21:17

您一次不能声明多个类。

将您的声明更改为

class CAStreamBasicDescription;
class FFTBufferManager;

编译器正在寻找 unqualified-id 因为它认为您正在声明 CAStreamBasicDescription 类型的变量,因此它需要您给出的变量名称它是一个逗号。

You can't declare more than one class at a time.

Change your declarations to

class CAStreamBasicDescription;
class FFTBufferManager;

The compiler is looking for an unqualified-id because it believes that you're declaring a variable of type CAStreamBasicDescription, so it expects a variable name where you gave it a comma.

溺ぐ爱和你が 2024-12-10 10:21:17

看起来您正在尝试创建一个 Cocoa 框架之一中已存在的类。

Looks like you are trying to create a class that already exists in one of the Cocoa frameworks.

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