我目前正在开发一款游戏,我正在使用苹果游戏中心的回合制游戏 api。我一直在尝试使用 c 结构来最小化我通过 Game Center 发送的数据的大小。
我有一个包含回合数据的结构,一个包含有关当前回合的信息的结构,它还有一个包含所有其他回合的数组。
但是我希望数组是动态的,所以我可以轻松地遍历它,我决定使用 c++ 向量,但它不起作用。
到目前为止,这是我的代码:
标题:
.h
#import <vector>
typedef struct {
int points; //Points that the player got in this round
int round; // the round number for this turn
char* playerID; //Who's turn was this?
} TurnData ;
typedef struct {
std::vector<TurnData>* turns; //Keep a list over all turns
int currentRound; //What round is it now?
int maxRounds; //How many rounds for this game?
} GameData;
测试实现:
.m
+(void)test {
GameData data;
data.currentRound = 1;
data.maxRounds = 2;
TurnData turnData;
turnData.round = data.currentRound;
turnData.points = 100;
turnData.playerID = "playerID";
data.turns->push_back(turnData);
GameData loadData = data;
for (std::vector<TurnData>::iterator it = loadData.turns->begin(); it != loadData.turns->end(); ++it) {
NSLog(@"Player: %c, points: %d, round: %d", it->playerID, it->points, it->round);
}
}
当我运行它时,我收到一条错误消息“词法或预处理器错误。找不到‘向量’文件”
任何帮助深表感谢。