c - C 中另一个结构体内部的结构体

标签 c struct

我需要做这样的事情:

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/

相关文章:

c - PS/2 键盘不会发送按键中断,但会响应命令

c++ - 如何定义多个源文件访问的linux内核变量?

c - 如何处理 typedef 结构中的循环依赖

C:在单独的函数中操作结构

c - 使用结构时出错,C

c - 通过函数传递结构

c - C中 'or'和 'and'运算符的优先级

c - while(i--) 通过 gcc 和 clang 优化 : why don't they use sub/jnc?

c - JNA 写入 stdout 时内存访问无效

c - 将文件读入结构体