相关疑难解决方法(0)

C中的opaque(抽象)数据类型

文件api.h

#include <stdio.h>
#ifndef API
#define API

struct trytag;
typedef struct trytag try;

void trial (try *);

#endif
Run Code Online (Sandbox Code Playgroud)

文件core.h

#ifndef CORE
#define CORE
struct trytag
{
    int a;
    int b;
};
#endif
Run Code Online (Sandbox Code Playgroud)

文件func.c

#include "api.h"
#include "core.h"

void trial (try *tryvar)
{
    tryvar->a = 1;
    tryvar->b = 2;
}
Run Code Online (Sandbox Code Playgroud)

文件main.c

#include "api.h"

int main ()
{
    try s_tryvar;

    trial(&s_tryvar);

    printf("a = %d\nb = %d\n", s_tryvar.a, s_tryvar.b);
}
Run Code Online (Sandbox Code Playgroud)

当我编译时,我得到:

main.c:5: error: storage size of ‘s_tryvar’ isn’t known
Run Code Online (Sandbox Code Playgroud)

如果我core.hmain.c …

c types abstract

0
推荐指数
1
解决办法
3228
查看次数

标签 统计

abstract ×1

c ×1

types ×1