Getting compiler error when removing typedef in a C++ struct
Initially I had the following.
struct A: public B
{
};
typedef struct A C;
Now, I changed that into
typedef struct: public B
{
} C;
and I get a link error for all functions getting
fun(C*)
开发者_StackOverflow
as a parameter.
How can I fix this problem?
I'm not totally sure, but a couple ideas: You can't forward declare typedefs, so if someone was forward declaring A
that could cause issues (even if it seems unrelated).
I suspect the real problem is because you're typedef
ing the struct instead of naming it. Almost certainly this is causing the compiler to give it different linkage (for example it gets different decorated name in each file) and it can't find the appropriate functions.
Finally, since you're using inheritance this must be C++, so you probably shouldn't be using typedef
for your struct
s at all.
精彩评论