错误:“类名”重新声明为不同类型的符号?
我遇到了与此 问题
我通过在 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我猜你同时使用 C++ 和 Objective-C。
我建议重命名所有包含 Objective-C 和 C++ 代码的
.cpp
和.m
文件,以使用扩展名.mm
- 这告诉编译器使用“Objective-C++”规则,并且会阻止很多编译器麻烦。另外,
CAStreamBasicDescriptpion
似乎是一个 C++ 类 - 您必须使用class CAStreamBasicDescriptpion;
来转发声明它,而不是@ class CAStreamBasicDescriptpion;
(注意,没有“at”符号)- 第二种形式仅适用于前向声明 Objective-C 类。我怀疑这是您观察到的特定错误的根本原因。编辑回应评论:我不确定您的第一个新问题 - 只要
FFTBufferManager
和CAStreamBasicDescription
都可以正常工作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 withclass 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
andCAStreamBasicDescription
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 ofCAStreamBasicDescription
here, and the compiler needs to know its structure to do so.您一次不能声明多个类。
将您的声明更改为
编译器正在寻找
unqualified-id
因为它认为您正在声明CAStreamBasicDescription
类型的变量,因此它需要您给出的变量名称它是一个逗号。You can't declare more than one class at a time.
Change your declarations to
The compiler is looking for an
unqualified-id
because it believes that you're declaring a variable of typeCAStreamBasicDescription
, so it expects a variable name where you gave it a comma.看起来您正在尝试创建一个 Cocoa 框架之一中已存在的类。
Looks like you are trying to create a class that already exists in one of the Cocoa frameworks.