-
June 13th, 2012, 12:56 PM
#1
[RESOLVED] Forms Singleton with Cyclic #Include ?
Hi
Iam using VC++2010. Earlier I learned from here but Iam facing the problem with Cyclic Include,
Any Ideas will be verymuch helpful to me... Thanks
Actually Form1 Codes
#include "Form2.h"
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Form2^ MyEmpLoan= Form2::GetForm(true,this);
MyEmpLoan->MdiParent=this;
MyEmpLoan->FormBorderStyle=System::Windows::Forms::FormBorderStyle::None;
MyEmpLoan->Dock=DockStyle::Fill;
MyEmpLoan->Show();
}
Form2 Codes
#include "Form1.h" //Its required because It's my MDIParent..I Need it's ToolStrip & Functions
public: static Form2^ Form2::_instance = nullptr;
public: static Form2^ Form2::GetForm(bool IsMDIChild, Form1^ MyInstFrm) {
if (_instance == nullptr)
_instance = gcnew Form2();
if (_instance->IsDisposed)
_instance = gcnew Form2();
if (IsMDIChild)
_instance->MdiParent = MyInstFrm;
return _instance;
}
But its giving below error
error C2065: 'Form2' : undeclared identifier
error C2065: 'MyEmpLoan' : undeclared identifier
error C2653: 'Form2' : is not a class or namespace name
Thanks
-
June 14th, 2012, 04:40 AM
#2
Re: Forms Singleton with Cyclic #Include ?
Move both forms implementation to .cpp file. By default, Windows Forms designer places all code to h-file (possibly because it works by the same algorithm for all .NET languages).
Having implementation in .cpp file, you can use forward declaration in .h file, and include both .h files to .cpp - standard C++ way to resolve circular dependencies.
-
June 14th, 2012, 07:11 AM
#3
Re: Forms Singleton with Cyclic #Include ?
Hello Alex,
Thanks For The Help...
Can you alter my code please....? will be very helpful, Because its my first project....
Thanks Again
-
June 14th, 2012, 12:10 PM
#4
Re: Forms Singleton with Cyclic #Include ?
Look at your project: you can see that Form1.h is included to Form1.cpp, which contains the only line:
Now move implementation to .cpp file by common C++ rules:
Code:
// Form1.h
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e);
// Form1.cpp
System::Void Form1::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
Form2^ MyEmpLoan= Form2::GetForm(true,this);
MyEmpLoan->MdiParent=this;
MyEmpLoan->FormBorderStyle=System::Windows::Forms::FormBorderStyle::None;
MyEmpLoan->Dock=DockStyle::Fill;
MyEmpLoan->Show();
}
Do the same with Form2. Now, move
#include "Form2.h"
from Form1.h to Form1.cpp. Only if necessary, add forward declaration to Form1.h:
ref class Form2;
Do the same with Form2.
Last edited by Alex F; June 14th, 2012 at 12:12 PM.
-
June 15th, 2012, 06:22 AM
#5
Re: Forms Singleton with Cyclic #Include ?
Alex....Thanks for the great help...! I get clear...Thanks Again....
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|