Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Member access into incomplete type error

Tags:

c++

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.

like image 578
SIMEL Avatar asked Dec 24 '22 23:12

SIMEL


1 Answers

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

like image 119
Marco A. Avatar answered Jan 08 '23 08:01

Marco A.