Forward declaration struct member access

146 Views Asked by At

I have a forward declaration of a struct in .h file and full declaration of the same struct in .c file. I want to access it's members, but I get

member access into incomplete type struct channel Here is my code:

verbs.h

struct channel;

verbs.c

struct channel{
    int index=10;
};

main.cpp

#include "verbs.h"
...
struct channel* ch;
...
ch->index;

verbs.h and verbs.c are legacy code, so I can't change them. Is there a way I can solve this problem?

1

There are 1 best solutions below

1
KamilCuk On

so I can't change them

Is there a way I can solve this problem?

Create verbs2.h with the copied content from verbs.c.

verbs2.h

struct channel{
    int index=10;
};

And just #include "verbs2.h".