Why should I have a forward statement?
eg
-Defines a class A, which uses object B of Class B, and then defines a Class B, which also contains an object A of Class A, as follows:
// a.h " B.h " class A { .... Private : b b; }; // b.h " a.h " class B { .... Private : A;
A compilation, there is a problem with each other , the solution is to declare Class B in the a.h file, and then use a pointer to B.
// a.h // #include "b.h" class B; class A { .... Private : b b; }; // b.h " a.h " class B { .... Private : A; };
Benefits of the predecessor statement:
-When we use the predecessor Declaration of Class B in Class A, when we modify Class B, we only need to recompile class B, without recompiling A.H's
-Of course, when you really use Class B, you must include the B.h
-Therefore, when you define a header file, you can rely on the predecessor declaration to not rely on the definition, and, where appropriate, should use a type of pre-declaration to reduce the header file import.
eg
-When a pointer member of a class is defined in a header file, the pointer is a pointer to another type class account that is defined in the project account* M_account;
-then add the preceding declaration before the class declaration of the header file: class account;
-OK, without having to include the header file where the account is located
Conditions of use of the predecessor declaration:
-assuming class xxx is in Xxx.h, the following three scenarios can be used with the predecessor declaration without the inclusion of xxx.h
-1. A function declaration with a parameter or return type of XXX;
-2. Class static members of type XXXT;
-3. Class member variable declared as xxx* or xxx&;
-Need to include xxx.h in several cases
-1. If there is a non-static member in your class that defines type XXX
-2. Your class inherits XXX's words
Attention:
-Just about to understand, there are a lot of unclear places
-To be Continued ...
Reference:
-http://blog.csdn.net/moxiaomomo/article/details/8083199
-http://qimo601.iteye.com/blog/1406992
C++_ front-facing statement