How to pre-declare a typedef class in C ++

For example, class A has a member of class B. In general, in order to minimize compilation dependencies, we often make class A include B pointer and pre-declare class B in the declaration of class A. It looks like this:

//B.h
class B
{
    ....
};

//A.h
class B;
class A
{
    B*b;
    A();
    ...
};

//A.cpp
#include "B.h"
A::A()
{
    b=new B();
    ...
};

But now I have a question: if class B is defined using typedef as follows:

typedef class
{
 ....
}B;

The previous previously declared method will not work in this case. How should I pre-declare class B in Ah?

+4
source share
1 answer

In code, typedef class { .... } B;this is an unnamed class, and it Bis a type alias for an unnamed class.

(.. ); , B typedef .

, typedef. typedef , , .

: "pre-declare". ++ "pre-declare" "forward-declare". . , ", ", .

+2

Source: https://habr.com/ru/post/1659484/


All Articles