Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Form Circular Reference?

Form Circular Reference?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thenutz72
    wrote on last edited by
    #1

    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

    C I 2 Replies Last reply
    0
    • T thenutz72

      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

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      You should post this question in the Managed C++ forum.

      Cédric Moonen Software developer
      Charting control [v1.5] OpenGL game tutorial in C++

      1 Reply Last reply
      0
      • T thenutz72

        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

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups