我已经看到过有关指向对方的结构的问题,我尝试了很多东西,但是我无法解决我的问题。我的大脑正在燃烧!互相引用的结构
我有两个不同的结构/类型:set_t
和node_t
#ifndef _SETH_
#define _SETH_
#include "node.h"
#include "list.h"
typedef struct {
list_t* list;
}set_t;
set_t* createSet(node_t*);
set_t* findSet(node_t*);
set_t* unionSet(node_t*, node_t*);
#endif
我没有在我的set_t结构的任何node_t,但我用node_t作为参数,所以我包括node.h,你可以看到。列表是一个链接的节点列表,但目前这与我的问题没有关系。
#ifndef _NODEH_
#define _NODEH_
//?? #include "set.h"
typedef struct set_t s;
typedef struct node_t{
int color;
int dist;
int key;
int date;
int end;
s* set;
struct node_t* father;
}node_t;
node_t* createNode(int);
#endif
在beggining,我使用包括node.h set.h,因为我在我的节点结构使用一组。但是我对这些包含了一些“循环”。 所以I'im尝试使用此指令:
typedef struct set_t s;
,以避免这个循环的问题。
但是,这一次我有一个问题/警告,我想我明白: 当我这样做(让我们假设我们有一个node_t * N):
set_t* s = (set_t*)malloc(sizeof(set_t));
n->set= s;
我有不兼容的一个assignement指针类型的警告,也许是因为s是一个set_t *,但n->设置为* ...
我在做什么错?我真的想知道这是如何工作的,当你想在xh中包括xh在yh和yh中时... 同样的事情,如果yh需要xh,zh需要yh,而xh需要zh .. 我真的很希望我足够清楚为你们帮助我。
http://stackoverflow.com/questions/888386/resolve-circular-typedef-dependency。不要投入malloc返回。 'void *'做这项工作。不要键入一个结构两次。只在一个标题中进行。 – Stargateur