我有以下文件结构,其中包含一个封装类型的结构的定义,当我尝试访问该结构的成员时,我得到 Member access into incomplete type
错误。问题是什么?
foo_encoder.c :
#include "foo.h"
//...
struct FooEncoder {
int A;
int B;
foo_int32 C;
//...
}
foo.h :
extern "C" {
typedef struct FooEncoder FooEncoder;
//...
}
foo_interface.h :
typedef struct MyFooEncInst FooEncInst;
foo_interface.cc :
#include "foo_interface.h"
#include "foo.h"
//...
struct MyFooEncInst {
FooEncoder* encoder;
};
//...
MyFoo_Encode(FooEncInst* inst,...) {
//...
if (d > inst->encoder->C) { // This is where I get the error
//...
}
foo_int32
在另一个地方定义。
原文由 SIMEL 发布,翻译遵循 CC BY-SA 4.0 许可协议
您正在请求
FooEncoder
结构中的成员,该结构在 _foointerface.cc 文件的任何位置均不可见。这看起来类似于 pimpl idiom 。为了让您的代码了解
FooEncoder
的结构,您需要在你的 _foointerface.cc 文件中(我很不喜欢这个解决方案,你也没有发布完整的代码)或将你的结构定义移动到头文件中的其他位置并包含那个(推荐)。