Pius Friesch
Pius Friesch

Reputation: 359

enum included with header | Error not declared

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_ */

I have no clue why the enum game_status is not declared. I have included the header properly and it is in the scope, isn't it? I cant declare the enum in the "Player.h" eiter. I would have declared it twice. Can you help me please? Do you have any suggestions?

(I am not allowed to use C++11)

Thanks in advance

Upvotes: 1

Views: 6559

Answers (2)

Raxvan
Raxvan

Reputation: 6505

The problem is that you include Player.h that includes Maumau_game.h that tries to include Player.h and at that last include the definition is not present.

One way to fix this is to forward declare the enum in Player.h (by adding a line enum game_status) , remove the include for Maumau_game.h (from Player.h) and change the argument from game_status g_status to const game_status& g_status in do_turn function.

Upvotes: 5

Luchian Grigore
Luchian Grigore

Reputation: 258618

The problem is a circular include, remove the

#include "Player.h"

from Maumau_game.h and it should work. Only include what you need and forward-declare anything you can.

Upvotes: 7

Related Questions