gpt4 book ai didi

ios - 编译器错误 - iOS "expected ")"before "问题

转载 作者:行者123 更新时间:2023-11-28 19:22:45 25 4
gpt4 key购买 nike

下面的代码有什么问题? Xcode 4 说带有“Question”的两个方法声明由于“Question”之前的“预期”)而无法编译;消息,如以下代码中的注释所示。Question 类编译并且此代码以前一直在工作。我对问题进行了一些更改,但将它们撤回以尝试找出此编译时错误。

#import <Foundation/Foundation.h>
#import "Question.h"

@interface AppState : NSObject {

int chosenAnswer;
int correctAnswers;
int currentQuestionNumber;

// this will contain the hash table of question objects
NSMutableDictionary *questionHash;

}

@property (nonatomic) int chosenAnswer;
@property (nonatomic) int correctAnswers;
@property (nonatomic) int currentQuestionNumber;
@property (nonatomic, retain) NSDictionary *questionHash;

- (void) printQuestions;
- (void) printDescription;
- (void) addQuestion: (Question *) question; // <==== error
- (int) numberOfQuestions;
- (void) saveState;
- (void) resetState;
- (Question *) currentQuestion; // <===== error


@end

这是问题.h:

#import <Foundation/Foundation.h>

#import "AppState.h"

@interface Question : NSObject {

NSString *questionTxt;
int correctAnswer;
int number;

// this will contain the hash table of questions_answer objects
NSMutableDictionary *answerHash;

}


@property (nonatomic, retain) NSString * questionTxt;
@property (nonatomic) int correctAnswer;
@property (nonatomic) int number;
@property (nonatomic, retain) NSMutableDictionary *answerHash;


-(void) addAnswer: (NSString *) answer;
- (NSMutableArray *) answerArray;
- (void) printDescription;
- (void) printAnswers;
- (NSString *) correctAnswerText;
- (Question *) currentQuestion;

@end

最佳答案

循环依赖? AppState 正在导入 Question,而 Question 正在导入 AppState。

转发声明其中之一以打破循环,例如在你的 AppState @interface 语句之前使用 @class Question,就像这样

@class Question;

@interface AppState : NSObject {

int chosenAnswer;
int correctAnswers;
int currentQuestionNumber;

// this will contain the hash table of question objects
NSMutableDictionary *questionHash;
}
...

相关问题:@class vs. #import

关于ios - 编译器错误 - iOS "expected ")"before "问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7276418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com