Ilya Melamed Ilya Melamed - 11 days ago 5
C++ Question

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
//...
}


foo_int32
is defined in another place.

Answer

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).

Comments