There is an understanding that I have problems with the switches. At the moment there is a program with 4 forms and a bunch of classes. I listed all the classes in a separate .h file and refer to it in the forms. #Include "includes.h" The problem is that over time, classes and forms accumulated in the program and includes.h grew. Classes began to intersect, one uses the other and the third is called in the other. The program works, but I had to embed #include "includes.h" already in the .h file of each form, because at some point the .h form file stopped seeing this inclusion in the .cpp form file. As a result, classes are compiled 10 times for each connection, and as a result, compilation takes a lot of time. Can you please tell me how to register all inkludy correctly?
2 answers
Can you please tell me how to register all inkludy correctly?
First of all, as indicated in the remote message - you need to use the include-guard method, preferably in the form of #pragma once . This is a more modern way. And it will give the possibility of a single inclusion of headers.
The second point is the analysis with "business logic". When classes work "all-with-all", this is obviously a buggy salad. It is necessary to determine "who interacts with whom." If there are cross-interactions, use forward announcements. In principle, one of the solutions is proactive announcements and they need to be submitted separately, even if in global_include.h . For example:
#pragma once class ClassDrinkVodka; class ClassRunToMaidan; class ClassJumpForPeremoga; class ClassZradaCry; Here the interaction sequence is not defined in advance. And this file can be included globally. And headers-implementation - as necessary. Build systems themselves will be looking for the situation, what is changed and what is required to be copied.
But the best thing for one class is one pair ( *.h and *.cpp ) of files. Several classes in the file are justified only if extremely local functionality is solved.
Can and
#pragma once or you can wrap the whole .h file in
#ifndef INCLUDES_H #define INCLUDES_H // все содержимое #endif // INCLUDES_H The second option in this case is just as good, but in general it is better, since it is much more common.
And yet it is really better to decide who needs what class, and accordingly include includ