I want to go around, because I want to do a QT project and pick up C ++ again. This is a programming tool for the first language for me.
It was the first time that I was responsible for designing the project architecture. It was a bit excited and confused. But fortunately, I feel like I am coming over. The basic structure design document has been written and the basic engineering framework has been set up, and the formal coding phase will soon be available.
One of the gains of Writing module-class files today is that when defining header files, do not rely on definitions if they depend on the pre-declaration, at the same time, you should use the pre-declaration of the type to reduce the import of header files when appropriate. For example, when a pointer member of a class is defined in the header file, the pointer is another type defined in the project.Class
A pointer to an account.Account*
M_account ;. Add the pre-declaration before the class declaration of the header file:
Class account;
It is OK, and you do not need to include the header file of the Account:
# Include "account. H" // The pre-declaration replaces this import Method
What are the benefits of doing so?
You can use the pre-declaration to reduce the header files to be included. When a header file is included, a new dependency is introduced. As long as the dependent header file is modified,CodeIt will be re-compiled. This dependency will be recursively transmitted, that is, header file B containing header file a. When header file a is changed, header file B and all header files containing header file B will be re-compiled. Therefore, this situation should be appropriately reduced.
However, the pre-declaration of the type is conditional. Suppose there is a test class. If your class has a non-static member defining the test type, or your class inherits the test class, you must include the header file where test is located, but cannot use the pre-declaration of the test class. In three cases, you can use the test class instead of accessing the test definition body:
(1) parameter or function declaration with the return type of test;
(2) Static Class Members of the test type;
(3) declare a class member variable as test * or Test &;
Progress comes from summing up, warming up and updating. This is the truth ~