2 headers files that need to include each other... ?!
-
Hey everybody I have a weird scenario that requires that 2 header file will include each other, and I'm not sure how should I do that. I'll explain... I have 2 Form: mainForm (mainForm.h) and subForm (subForm.h). The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it. Now, the subForm, which is non-modal, can change things on the mainForm (for example, a button that displays text on the mainForm), meaning that subForm must have access to mainForms public functions -> in other words, I must include mainForm.h in subForm. How can I perform something like that in C++ without getting into that problem?! Thanks!
-
Hey everybody I have a weird scenario that requires that 2 header file will include each other, and I'm not sure how should I do that. I'll explain... I have 2 Form: mainForm (mainForm.h) and subForm (subForm.h). The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it. Now, the subForm, which is non-modal, can change things on the mainForm (for example, a button that displays text on the mainForm), meaning that subForm must have access to mainForms public functions -> in other words, I must include mainForm.h in subForm. How can I perform something like that in C++ without getting into that problem?! Thanks!
Green Fuze wrote:
The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it.
You can always use a pointer to the dialog class instead of an instance of the dialog class. This way, you only need to put a forward declaration in your header file. See here[^] for instance.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Hey everybody I have a weird scenario that requires that 2 header file will include each other, and I'm not sure how should I do that. I'll explain... I have 2 Form: mainForm (mainForm.h) and subForm (subForm.h). The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it. Now, the subForm, which is non-modal, can change things on the mainForm (for example, a button that displays text on the mainForm), meaning that subForm must have access to mainForms public functions -> in other words, I must include mainForm.h in subForm. How can I perform something like that in C++ without getting into that problem?! Thanks!
-
Green Fuze wrote:
The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it.
You can always use a pointer to the dialog class instead of an instance of the dialog class. This way, you only need to put a forward declaration in your header file. See here[^] for instance.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Green Fuze wrote:
The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it.
You can always use a pointer to the dialog class instead of an instance of the dialog class. This way, you only need to put a forward declaration in your header file. See here[^] for instance.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++Thanks! :-)
-
Make a common data object which is known to both Forms. If an Update is needed use a user defined message. I think this is also known as MVC (Model-View-Controller) Divide view and data!!! :cool:
Greetings from Germany
Thanks!!! sounds interesting...!
-
Hey everybody I have a weird scenario that requires that 2 header file will include each other, and I'm not sure how should I do that. I'll explain... I have 2 Form: mainForm (mainForm.h) and subForm (subForm.h). The mainForm opens a non-modal subForm -> meaning mainForm must include subForm.h in order to show it. Now, the subForm, which is non-modal, can change things on the mainForm (for example, a button that displays text on the mainForm), meaning that subForm must have access to mainForms public functions -> in other words, I must include mainForm.h in subForm. How can I perform something like that in C++ without getting into that problem?! Thanks!
what you want to do is include the header files from the source file that will be making use of these functions or classes. having header files include other header files can introduce circular dependencies and this will result in increasing the compile time. this is not a hard and fast rule, but one i follow most of the time. this way you include the source file once, where it is being used!
--- Yours Truly, The One and Only! web: devmentor.org Design, Code, Test, Deploy