我需要做这样的事情:
typedef struct a A;
typedef struct b B;
struct a{
B oi;
};
struct b{
A ola;
};
但是当我尝试编译时它返回此错误:
gustavo@depaula-ubuntu:~/Desktop/grafo$ gcc test.c
test.c:3:12: error: field ‘ola’ has incomplete type
struct a ola;
^
编辑: 我不认为这是一个 XY 问题,但我需要上面的代码(它不起作用):
typedef struct union util;
typedef struct graph Graph;
typedef struct vertex_struct Vertex;
typedef struct arc_struct Arc;
typedef struct graph{
Vertex * vertices;
} Graph;
typedef struct vertex_struct {
struct arc_struct * arcs;
int name;
struct util u, v, w, x, y, z;
};
typedef struct arc_struct {
struct vertex_struct * tip;
struct arc_struct * next;
struct util a, b;
};
struct union {
struct vertex_struct * V;
struct arc_struct * A;
struct graph_struct * G;
char * S;
int I;
};
最佳答案
你无法做你正在尝试的事情。
其中一个成员必须是指针。
struct a{
B* oi;
};
struct b{
A ola;
};
或
struct b{
A* ola;
};
struct a{
B oi;
};
关于c - C 中另一个结构体内部的结构体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37638093/