Form Circular Reference?
-
Hey, I am trying to open form2 from form1. Then open a new form1 when form 2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong because these are the automatically generated code for Forms in the .h file. /*Form1.h*/ #pragma once #ifndef First #define First #include "Form2.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^ frm = gcnew Form2; frm->Show(); this->Close(); } #endif /*Form2.h*/ #pragma once #ifndef Second #define Second #include "Form1.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 ^ frm = gcnew Form1; frm->Show(); this->Close(); } #endif
-
Hey, I am trying to open form2 from form1. Then open a new form1 when form 2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong because these are the automatically generated code for Forms in the .h file. /*Form1.h*/ #pragma once #ifndef First #define First #include "Form2.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^ frm = gcnew Form2; frm->Show(); this->Close(); } #endif /*Form2.h*/ #pragma once #ifndef Second #define Second #include "Form1.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 ^ frm = gcnew Form1; frm->Show(); this->Close(); } #endif
You should post this question in the Managed C++ forum.
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
Hey, I am trying to open form2 from form1. Then open a new form1 when form 2 is closed. But adding the #include "Form1.h" header to form2.h is causing errors (undeclared identifier). I added these inclusion guards and tried using forward declaration. EIther that didn't work or I used it wrong because these are the automatically generated code for Forms in the .h file. /*Form1.h*/ #pragma once #ifndef First #define First #include "Form2.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form2 ^ frm = gcnew Form2; frm->Show(); this->Close(); } #endif /*Form2.h*/ #pragma once #ifndef Second #define Second #include "Form1.h" private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { Form1 ^ frm = gcnew Form1; frm->Show(); this->Close(); } #endif
As Cedric said, there is a managed C++ forum - and you should be using it. But in C/C++, this would work:
class CTwo; // note we're just telling the compiler it exists
class COne
{
...
CTwo *m_pTwo; // good, but needs assigned somewhere
CTwm m_Two; // can't do this, as we don;t know anything about CTwo except that it exists
};class Two
{
...
COne *m_pOne; // good, but needs assigned somewhere
COne m_One; // We can do this, as COne has been fully defined.
};I hope that helps, Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!