错误:在Objective C中之前的期望说明符 - 限定符列表? [英] error: expected specifier-qualifier-list before...in Objective C?

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

问题描述

每当我构建以下代码时,我都会收到上述错误。

Whenever I build the following code, I get the error above.

//Controller.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
#import "PolygonView.h";

@interface Controller : NSObject
{
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
    IBOutlet PolygonShape *shape;
    IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end


//Controller.m
#import "Controller.h"


@implementation Controller
@end    

然而,当我替换import语句并改为使用前向类引用时,代码编译。

However, when I replace the import statement and put a forward class reference instead, the code compiles.

//Controller.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "PolygonShape.h"
@class PolygonView;

@interface Controller : NSObject
{
    IBOutlet UIButton *decreaseButton;
    IBOutlet UIButton *increaseButton;
    IBOutlet UILabel *numberOfSidesLabel;
    IBOutlet PolygonShape *shape;
    IBOutlet PolygonView *shapeView;
}
- (IBAction)decrease;
- (IBAction)increase;
- (void)awakeFromNib;
@end

//Controller.m
#import "Controller.h"
#import "PolygonView.h"

@implementation Controller
@end

任何人都可以解释一下吗?

Can anyone explain?

推荐答案

是的,我也有这个循环依赖的问题,我在彼此导入这两个类。我也不知道前方宣言是什么。我在维基百科上迅速搜索了它,但描述得很糟糕。我发现这篇文章解释了它们是什么以及它们与周期性进口的关系。 http://timburrell.net/blog/2008-11 -23 / effective-c-cyclical-dependencies /

Yes, I too had this problem of Cyclical Dependencies where I was importing both classes in each other. I also didn't know what Forward Declarations were. I promptly searched it on Wikipedia but it was poorly described. I found this post that explains what they are and how they relate to cyclical imports. http://timburrell.net/blog/2008-11-23/effective-c-cyclical-dependencies/

注意:链接一直在下降所以我只是 PDF'd

Note: The link keeps going down so I just PDF'd it.

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

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