About the prompt: invalid use of incomplete type

In GCC or g++, when two classes need to refer to each other:
If a pointer to another class is declared in a.h file of one class, the class keyword can be used to declare the pointer first, instead of including the header file.
However, if an object defining a class or a specific member of a class is involved, the header file for that class must be included and declared without the class keyword.
Otherwise, a compilation error as shown in the title will occur!

If we want to define A pointer to class B in the header file of class A, and we want to define A pointer to class A in class B, then we can use class B in class A
Declare, without needing to contain a header file of class B,
But when we need to call A method of class B, we need to include its header file, which can then be included in the.cpP file of class A
Header file #include < B.h> , and the same is true in class B

Read More: