无名结构的前置声明 [英] Forward declarations of unnamed struct

查看:245
本文介绍了无名结构的前置声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

赏金问题:所以,这两个是不一样的东西。精细。第二种形式是在一个库提供。 如何前瞻性声明是因为我不能改变呢?

Bounty question: So, these two Foos aren't the same thing. Fine. The second form is given in a library. How do I forward-declare it given that I can't change it?

我一直以为C和C ++允许重复提供报关单,有没有重复的定义。然后我试图写C ++ code延伸的C语言库时碰到这个问题来了。

I always thought C and C++ allowed repeated declarations provided that there were no repeated definitions. Then I came across this problem when trying to write C++ code which extends a C library.

struct Foo;
typedef struct {} Foo;

这提供了以下错误:

结构富'的previous宣布为'结构美孚

'struct Foo' has a previous declaration as 'struct Foo'

我要转发,申报的,该死!什么是错在这里?

I want to forward-declare, darn it! What's wrong here?

推荐答案

的typedef-ING匿名结构是pre-日期C ++ 03,主要面向以保持与pre-C99兼容实践编译器。

typedef-ing anonymous struct is a practice that pre-dates C++03 and is mainly oriented to retain compatibility with pre-C99 compilers.

由于这是2011年,并且这两个C ++和C都变了,我不知道为什么没有更多的先进的最新版本这样的库了!

Given that this is 2011, and that both C++ and C are changed, I wonder why there is no more up-to-date version of such a library!

如果它不是发展了,你不能假,而只是生存和改变它是这样做的方式。
如果您还有部署,提交问题给开发团队。

If it is not in development anymore, you cannot "leave", but just "survive" and change it is the way to do that. If still in deployment, submit the issue to the development team.

如果你需要一个解决办法,考虑到结构可以继承。
因此,写一个向前声明像

If you need a workaround, consider that struct can inherit. So, write a forward declaration like

struct MyFoo;

和它定义为

#include "old_library.h"
struct MyFoo: public Foo {};

而在所有code,忘掉并始终使用 MyFoo

这篇关于无名结构的前置声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆