包含标题的枚举|错误未声明

时间:2013-12-11 14:04:07

标签: c++ enums declaration

Maumau_game.h:

#ifndef MAUMAU_GAME_H_
#define MAUMAU_GAME_H_

#include <more_includes>
#include "Player.h"

enum game_status {
    STATUS_NONE = 0,
    STATUS_DRAW_2 = 1,
};

class Maumaugame_holder {
methods();
};

#endif /* MAUMAU_GAME_H_ */

Player.h:

#ifndef PLAYER_H_
#define PLAYER_H_

#include <vector>
#include "Maumau_game.h"
#include "Card.h"

class Player {
more_methods();

public:
    void do_turn(game_status g_status, const Card upper_dropped_card,
            Deck& talon); //Error: >>game_status<< not declared 


};

#endif /* PLAYER_H_ */

我不知道为什么没有声明枚举game_status。我已正确包含标题,它在范围内,不是吗?我无法在“Player.h”中声明枚举。我会宣布它两次。你能帮我吗?你有什么建议吗?

(我不允许使用C ++ 11)

提前致谢

2 个答案:

答案 0 :(得分:7)

问题是循环包含,删除

#include "Player.h"
来自Maumau_game.h

它应该可行。只包括你需要的东西,并向前宣告你能做的任何事情。

答案 1 :(得分:4)

问题是,您包含的Player.h包含Maumau_game.h,其中包含Player.h,并且最后包括该定义不存在。

解决此问题的一种方法是在Player.h中转发声明枚举(通过添加行enum game_status),删除Maumau_game.h的包含(来自Player.h)和在game_status g_status函数中将参数从const game_status& g_status更改为do_turn

相关问题