本文介绍了什么是c ++中的forward declaration?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说: / p>
This answer says:
typedef struct { ... } Foo;
声明一个匿名结构并为其创建一个typedef。因此,使用此构造,它在标签命名空间中没有名称,只有typedef命名空间中的名称。这意味着它也不能被前向声明。
declares an anonymous structure and creates a typedef for it. Thus, with this construct, it doesn't have a name in the tag namespace, only a name in the typedef namespace. This means it also can't be forward-declared. If you want to make a forward declaration, you have to give it a name in the tag namespace.
什么是转发声明?
推荐答案
Chad给出了一个非常好的字典定义。转发声明通常在C ++中用于处理循环关系。例如:
Chad has given a pretty good dictionary definition. Forward declarations are often used in C++ to deal with circular relationships. For example:
class B; // Forward declaration
class A
{
B* b;
};
class B
{
A* a;
};
这篇关于什么是c ++中的forward declaration?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!