我花了最后一小时查看具有相同错误的线程,但不完全相同的问题,所以我决定问自己。我正在为学校的一个项目工作。这是一个有多个头文件和cpp文件的游戏。我刚刚将文件从c文件转换为cpp文件,我正在努力将结构更改为类(对于赋值,它需要这样做)。
我收到以下错误: error
这是我的character.h文件:
#ifndef CHARACTER_H
# define CHARACTER_H
# include <stdint.h>
# include "dims.h"
# include "dungeon.h"
class character_t {
public:
char symbol;
pair_t position;
int32_t speed;
uint32_t alive;
uint32_t sequence_number;
uint32_t kills[num_kill_types];
};
int32_t compare_characters_by_next_turn(const void *character1, const void *character2);
uint32_t can_see(dungeon_t *d, character_t *voyeur, character_t *exhibitionist);
void character_delete(void *c);
#endif
这是我的dungeon.h文件:
#ifndef DUNGEON_H
# define DUNGEON_H
# include "heap.h"
# include "macros.h"
# include "dims.h"
# include "character.h"
class dungeon_t
{
public:
uint32_t num_rooms;
room_t *rooms;
terrain_type_t map[DUNGEON_Y][DUNGEON_X];
uint8_t hardness[DUNGEON_Y][DUNGEON_X];
uint8_t pc_distance[DUNGEON_Y][DUNGEON_X];
uint8_t pc_tunnel[DUNGEON_Y][DUNGEON_X];
character_t *character[DUNGEON_Y][DUNGEON_X];
character_t pc;
heap_t events;
uint16_t num_monsters;
uint16_t max_monsters;
uint32_t character_sequence_number;
uint32_t time;
uint32_t quit;
};
#endif
我知道要看很多,但不知道是什么造成了这种情况?我显然包括dungeon.h标题。我已经看到了圆形头部包含的提及,但我不明白当两个头部彼此需要时如何避免这种情况。
编辑: 我很感激帮助。你的答案比一小时左右的搜索更有帮助。在我甚至能够减少消息内容之前,你解决了我的问题。
答案 0 :(得分:1)
您遇到递归标头问题:dungeon.h
包括character.h
,而character.h
包含dungeon.h
。要解决此问题,您可以编写一个标头,其前缀声明为dungeon_t
,并将其包含在character.h
中。