我正在尝试为一个名为totheright的结构(这是一个链表节点)分配一个指针。指向结构/列表的指针当前位于另一个称为矩形的结构中。我试图这样做时遇到了一个错误。
currect->right = malloc(sizeof(totheright));
righthead = current->right;
以下是函数中的声明:
rect *currect = NULL;
totheright *righthead = NULL;
标题中的结构定义:
typedef struct _totheright {
int rect;
struct _totheright *right;
} totheright;
typedef struct _rect {
int thisrect;
struct totheright *right;
int left;
double width;
double height;
double xcord;
double ycord;
struct _rect *next;
} rect;
最佳答案
结构right
中的字段rect
在使用struct
或totheright
之前不应具有struct _totheright
:
typedef struct _rect {
int thisrect;
//struct totheright *right; // was
totheright *right; // fixed
//struct _totheright *right; // that would be ok as well
int left;
double width;
double height;
double xcord;
double ycord;
struct _rect *next;
} rect;