Expected specifier-qualifier-list before
I have the following Objective-C headers:
// Menu.h
#import <UIKit/UIKit.h>
#import "GameController.h"
@interface Menu : UIImageView {
GameController *gameController; // "Expected specifier-qualifier-list
// before GameController"
}
- (void)appear;
@end
and
// GameController.h
#import <UIKit/UIKit.h>
#import "Menu.h"
@interface GameController : UIView {
Menu *menu; // "Unknown type name 'Menu'"
}
- (void)startLevel0;
- (void)startLevel1;
开发者_JAVA技巧- (void)startLevel2;
@end
When I try to build the project, Xcode (v4) yells at me, saying Expected specifier-qualifier-list before GameController
and unknown type name 'Menu'
. I'm sure that they are somehow related, but I have no idea how?
It's not good practice to have mutually-including header files. Instead of importing Menu.h, use the @class
directive. Try removing #import "Menu.h"
and adding @class Menu
in its place. Ditto for Menu.h (remove GameController include, and add the @class
directive)
You have a circular reference in your imports. The compiler builds a dependency tree from the import statements so when two Classes rely on each other it doesn't know how to compile one before the other.
Sadly, gcc kicks out a fairly nonsensical error statement when this happens "Expected specifier-qualifier-list". @yan is correct that you should use the @class directive. Check out this question for a solid explanation: @class vs. #import
精彩评论