开发者

Error: Expected specifier-qualifier-list before 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 rele开发者_如何转开发vant 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:

Error: Expected specifier-qualifier-list before XXX


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

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

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".

To remove the circular dependency:

  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

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


The problem will be located in PiecesChoisies.h. Change:

 IBOutlet PiecesChoisies *piecesChoisies;

to

 IBOutlet NSString *piecesChoisies;

that will confirm that the problem is located in the .h file.


If this is in a header file, use

@class PiecesChoisies;

Instead of the import statement. Import the .h file in your .m file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜