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
//...
}
foo_int32
is defined in another place.
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.
In order to have your code aware of FooEncoder
's structure you need to either
#include "foo_encoder.c"
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With