What is forward declaration in c++?

c++, forward-declaration

Solution

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

Problem

This answer says: … Finally, ``` typedef struct { ... } Foo; ``` 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. What is forward declaration?

Original source

Related problems