结构定义中的预期 ' '

Expected ' ' in definition of struct

我现在正在做一个学校项目,我需要定义两个结构作为地址,如下面的代码所示:

typedef struct board_t* board;
/**
 * @brief Pointer to the structure that holds the game.
 */

typedef struct piece_t* piece;
/**
 * @brief Pointer to the structure that holds a piece
 */

如果我让它喜欢它,它就会编译。但是,一旦我尝试用括号替换分号来定义结构,就会出现编译错误。这是代码和错误:

typedef struct piece_t* piece{
/**
 * @brief Pointer to the structure that holds a piece
 */
 enum shape p_shape;
 enum size p_size;
 enum color p_color;
 enum top p_top;
 enum players author;
};


typedef struct board_t* board{
/**
 * @brief Pointer to the structure that holds the game.
 */
 piece array[4][4];
}

错误:

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
   53 | typedef struct board_t* board{

我需要做的是创建一个板,其中包含我可以在内部函数中编辑的部分。 谁能帮帮我?

我认为 typedef 名称需要放在最后

typedef struct piece_struct {
/**
 * @brief Pointer to the structure that holds a piece
 */
 enum shape p_shape;
 enum size p_size;
 enum color p_color;
 enum top p_top;
 enum players author;
}
piece;


typedef struct board_struct {
/**
 * @brief Pointer to the structure that holds the game.
 */
 piece array[4][4];
}
board;

如果您想要指针的 typedef 名称,则需要单独创建它们。

typedef piece* piece_ptr;
typedef board* board_ptr;

如果将结构定义与 typedef 分开,代码可能会更清晰:

struct piece_struct {
/**
 * @brief structure that holds a piece
 */
 enum shape p_shape;
 enum size p_size;
 enum color p_color;
 enum top p_top;
 enum players author;
};

typedef piece_str* piece;  // piece is a new name for a pointer
                           // to a piece_str

struct board_struct {
/**
 * @brief structure that holds the game.
 */
 piece array[4][4];
};

typedef struct board_struct* board;   // board is a new name for a pointer
                                      // to a board_str

我个人倾向于不为指针创建 typedef,因为我发现很难记住它是指针还是结构本身,所以我为结构创建了 typedef,并在声明指针时使用 *。