I have a third party C library with an anonymous structure similar to
typedef struct
{
...
}A;
This file is automatically generated through a program, thus can change based on something
Now in a C++ project I accept argument of above type, for example as
void foo(const A & in)
{
...
}
How do I forward declare A in the header file defining the above function?
I have tried :
typedef struct A A;
or
struct A;
and also
typedef A A;
out of curiosity.
However those result in compile time error of redefining the type. Thanks
Sadly you're out of luck.
A
is a typedef
for an untagged struct
. And you can't forward declare that since you can't refer directly to that struct
.
Can you change the generator so it outputs typedef struct A { ... } A;
? Then it would compile well in both C and C++, and you could forward declare that in C++.
Otherwise you have two options: 1. #include
the file containing the struct
declaration. 2. Copy the struct
by hand. Obviously (1) is much more preferable.
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