Итак, я получу ошибку выше нескольких раз в Visual studio. Вот мой код: Union.hошибка c2371 struct <type> redefinition
#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 **», например, а не как «struct CELL ** variable».
EDIT: Я добавил охранников как 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 СИНТАКСИСНОЕ ОШИБКА НЕИСПРАВНОСТИ '{' до '*' И C2143 СИНТАКСИСНАЯ ОШИБКА отсутствует ')' до '*'
Что происходит ??? !!!
[включить охранников] (https://en.wikipedia.org/wiki/Include_guard) необходимо поместить в включенный заголовок, то есть в Union.h, в UI.h и AI.h. Как есть, Union.h включен дважды! Один раз AI.h и один раз UI.h. – francis
AI.h включает Union.h, который включает AI.h? Курица или яйцо? –
Ответ @Joyas на вопрос http://stackoverflow.com/questions/17913871/c-forward-declaration-of-struct-in-header относительно прямого объявления структуры в c может помочь вам. – francis