CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2011
    Posts
    73

    [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

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    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.

  3. #3
    Join Date
    Dec 2011
    Posts
    73

    Smile 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

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    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:
    Code:
    #include "Form1.h"
    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.

  5. #5
    Join Date
    Dec 2011
    Posts
    73

    Cool 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
  •  





Click Here to Expand Forum to Full Width

Featured