【发布时间】:2016-05-03 09:34:41
【问题描述】:
所以,我在 Visual Studio 中多次收到上述错误。这是我的代码: Union.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef AI_H
#define AI_H
#include "AI.h"
#endif
#ifndef UI_H
#define UI_H
#include "UI.h"
#endif
typedef struct BOARD_CELL {
int player, wall, steps;
}CELL;
typedef struct {
int x, y;
}COORD;
AI.h
#include "union.h"
void pathfind(CELL **a, int n);
void ai(CELL **a);
void genmove(CELL **a);
UI.h
#include "union.h"
void cmdtoAct(char* c, CELL **a, char player_counter, COORD white_vertex, COORD black_vertex);
void placeWall( CELL **a, char* str, char* str2, int n);
void playmove( CELL **a, char *colour, char *vertex, COORD player_vertex);
int pathCheck( CELL **a);
void showBoard( CELL **a);
void backdoor();
char* getCmd();
关于 .c 文件,您只需要知道每个文件都必须知道 CELL 结构和 COORDS 结构的存在,并且由于它们是类型定义的,所以当我在我的函数中使用它们时例如,作为参数,我将它们称为“CELL **variable”,而不是“struct CELL **variable”。
编辑:我为 ai.h 和 ui.h 添加了警卫,如下所示: AI.h
#ifndef AI_H
#define AI_H
#include "union.h"
#endif
void pathfind(CELL **a, int n);
void ai(CELL **a);
void genmove(CELL **a);
UI.h
#ifndef UI_H
#define UI_H
#include "union.h"
#endif
void cmdtoAct(char* c, CELL **a, char player_counter, PLAYER white, PLAYER black);
void placeWall( CELL **a, char* str, char* str2, int n);
void playmove( CELL **a, char *colour, char *vertex, PLAYER player);
int pathCheck( CELL **a);
CELL **boardsize(struct CELL **a, int size);
void showBoard( CELL **a);
void backdoor();
char* getCmd();
现在我得到一个 C2143 SYNTAX ERROR MISSING '{' before ' * ' 还有一个 C2143 SYNTAX ERROR 在 ' * ' 之前缺少 ')'
这是怎么回事???!!!
【问题讨论】:
-
include guards 必须放在包含的头文件中,即在 Union.h 中,在 UI.h 和 AI.h 中。按原样,Union.h 包含两次!一次是 AI.h,一次是 UI.h。
-
AI.h 包含 Union.h,其中包含 AI.h?鸡还是蛋?
-
@Joyas 对stackoverflow.com/questions/17913871/… 关于 c 中结构前向声明的问题的回答可能会对您有所帮助。
-
@francis,请看编辑!我疯了!!!
标签: c syntax-error visual-studio-debugging