I have a class that is only used in one specific part of another class. It is not mentioned in any other parts of the main class. And I include the corresponding header at the top of a file.
Is there any way to "uninclude" the header after I've used it?
What I mean, is that after you "uninclude" the header with the class, references to the class would not be defined, and any calls to the class would throw an error when compiling.
Pseudo-code:
// code section where "cubeData" should be visible
#include "CubeData.h"
void mainWidget::createGeoObjects() {
cube = new cubeData();
// ...
}
// #uninclude "CubeData.h" - ???
//
// code section where "cubeData" should be invisible
void mainWidget::otherFunction() {
cube = new cubeData(); // should result in a compile error
// ...
}
The effect of unincluding a header half way through a code file, into which you have included the header at the file start, is supposed to be that the code in the second half acts as if the header has not been included.
This can be achieved by splitting the code file into two parts.
First part includes the header in question (and probably some other headers).
Second part does NOT include the header (but the others again, so that their content IS known).
You might have to put anything from the first half which needs to be visible in the second half into a new header and also include that into both parts.
So in short, create two code files and include what you need into them. Especially do not include what you do not want to be visible.
No.
Part of this is that includes are part of the preprocessor. For the actual compiler, code from an included file and code from the including file look the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With