错误:XXX之前的预期说明符限定符列表 [英] Error: Expected specifier-qualifier-list before XXX

查看:372
本文介绍了错误:XXX之前的预期说明符限定符列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它做了这么多次,我没有遇到任何问题,但这次我仍然得到上面的错误,我的相关代码是这样的:

it did it so many times and i didn't had any problems with it, but this time i still getting the error above, my relevant code is this:

#import "PiecesChoisies.h"

@interface SelectionMobilier : UIViewController {
IBOutlet PiecesChoisies *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies 
}
@end

提前填写任何建议:)

Thanx in advance for any suggestions :)

编辑:
我试试这个:

EDIT : I try this :

#import "PiecesChoisies.h"

    @interface SelectionMobilier : UIViewController {
    IBOutlet NSString *piecesChoisies;//Error: Expected specifier-qualifier-list before PiecesChoisies 
    }
    @end

现在我得到了这个堆栈:

Now i got this stack:

推荐答案

PiecesChoisies 未被识别为类型。这可能发生,因为它具有周期性依赖性。

PiecesChoisies is not recognized as a type. This may happen because it has cyclical dependencies.

以下代码示例说明了该问题。类A和B创建循环依赖项,尝试相互导入。

The following code example illustrates the problem. Classes A and B create a circular dependency trying to import each other.

#import "B.h"               // <-- A imports B
@interface A : NSObject
@end

#import "A.h"
@implementation A
@end


#import "A.h"              // <-- and B imports A
@interface B : NSObject
@end

#import "B.h"
@implementation B
@end

因为从未创建过类,编译器会将它们视为未知标记,因此错误显示为 XXX 之前的预期说明符限定符列表。换句话说我期待XXX之前有意义的东西。

Because the classes are never created, the compiler treats them as unknown tokens, so the error shows as Expected specifier-qualifier-list before XXX. In other words "I expected something meaningful before XXX".

删除循环依赖:


  1. 并添加一个前向类声明(接口文件中的 @class )。

  2. #import 从界面移动到实现文件。

  1. And add a forward class declaration (@class) on the interface file.
  2. Move the #import from the interface to the implementation file.

类声明告诉编译器别担心,我稍后会定义,因此标题可以安全导入因为冲突的定义现在在实现文件上看不见了。

The class declaration tells the compiler "don't worry, I'll define this later", so the header becomes safe to import because the conflicting definition is now out of sight on the implementation file.

这是上一个例子的结果:

Here is the result for the previous example:

@class B;             // <---- #import "B.h" replaced with @class B
@interface A : NSObject
@end

#import "A.h"
#import "B.h"         // <---- #import "B.h" added
@implementation A
@end

并且对B类做同样的事情:

And do the same with class B:

@class A;             // <---- #import "A.h" replaced with @class A
@interface B : NSObject
@end

#import "B.h"
#import "A.h"         // <---- #import "A.h" added
@implementation B
@end

这篇关于错误:XXX之前的预期说明符限定符列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆