开发者

Getting compiler error when removing typedef in a C++ struct

开发者 https://www.devze.com 2023-03-29 00:41 出处:网络
Initially I had the following. struct A: public B { }; typedef struct A C; Now, I changed that into typedef struct: public B

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 typedefing 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 structs at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消