Introducing another class into a header file is often written in two ways:
(1) class Name;
(2) #include "Name.h"
What is the difference between them?
The first one is called forward declaration, name is an incomplete type (incompete Type), known as name is a type, but does not know which members are included. an incomplete type can only be used in a limited way, cannot define an object of that type, the incomplete type can only be used to define pointers and references to that type, or to declare (rather than define) a function that uses that type as a formal parameter type or return type. (The forward declaration only knows that there is one class, but the specific information is unknown); In addition, it can Eliminate compilation dependencies and reduce the time it takes to compile (if # Include "Name.h" once the definition of Name needs to be modified, Name.h will be recompiled, Causes all files that use Name.h to be recompiled, which results in a compilation dependency, which increases the time to compile, and, in large projects, it can even significantly increase compilation time if there are many such places. )
The second include header file associates the entire header file with where it is used, so you can know the specific information about the class. at the time of compiling the Name.h file directly, so the interface can be used, you can declare the object, call method.
Forward declarations and # include differences for the basic (20) C + + base class