我可以帮你翻译成如下内容:
使用 Codeblocks 编译我的项目时出现了错误。
问题出在一个枚举定义和一个结构体定义上。
它们都在一个头文件中定义,在我只在 .c 文件中使用这些枚举和结构体时能够正常工作。但是当我在另一个 .c 文件中包含该 .h 文件时,就会出现错误。以下是一些代码:
maps.h
#include <stdlib.h>
#include <stdio.h>
enum Property { BACKGROUND, FOREGROUND, BLOCK, EVENT };
typedef struct {
char map_name[50];
int width;
int height;
char* map_struct;
}rpgMap;
char getTileProperty(rpgMap map, int x, int y, int property);
maps.c
#include "maps.h"
char getTileProperty(rpgMap map, int x, int y, int property){ // Works
char value = NULL;
value = map.map_struct[(((y*(map.width-1))+y+x) * 4 ) + property];
return value;
}
rpgMap loadMap(unsigned char* map){
rpgMap Map;
//....
//some code
//...
return Map;
}
// This works until i include maps.h in another .c file
以下是翻译的结果:
所以这里的问题是,当我在eg. game.c或game.h中包含maps.h时,我遇到了这个错误:
错误:'enum Property'的嵌套重新定义
我不明白!
#pragma once
(我认为这会有帮助) - elyashiv