成员访问不完整类型错误 [英] Member access into incomplete type error
问题描述
我有以下文件结构,其中包含一个封装类型的结构定义,当我尝试访问该结构的成员时,我将成员访问权限转换为不完整类型
错误。问题是什么?
I have the following files structure that contain the definition of a struct an encapsulating type, when I try to access a member of the struct, I get the Member access into incomplete type
error. What is the problem?
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
//...
}
$ b的地方$ b
foo_int32
是在另一个地方定义的。
foo_int32
is defined in another place.
推荐答案
您要在 FooEncoder
结构中寻找成员,该成员在 foo_interface.cc 文件中的任何位置都不可见。这看起来类似于 pimpl惯用语。
You're asking for a member in the FooEncoder
struct which isn't visible anywhere in your foo_interface.cc file. This looks similar to a pimpl idiom.
要使您的代码了解 FooEncoder
的结构,您需要
In order to have your code aware of FooEncoder
's structure you need to either
#include "foo_encoder.c"
在您的 foo_interface.cc 文件(我非常不喜欢这种解决方案,您也没有发布完整的代码),或者将结构定义移动到头文件中的其他位置,并包括该结构定义(推荐)。
in your foo_interface.cc file (I quite don't like this solution and you didn't post the full code either) or move your struct definition elsewhere in a header file and include that one (recommended).
这篇关于成员访问不完整类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!