开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜