c++ cli - visual studio 2010 C++, Including windows form recurrly -


i using visual studio 2010. have 2 windows form calls each other. form1 has include form2

i read can not include form1 in form2 again. instead use ref class form1.

but getting following error

c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(85): error c2512: 'spl_project::form1' : no appropriate default constructor available 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(86): error c2027: use of undefined type 'spl_project::form1' 1>
c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(11) : see declaration of 'spl_project::form1' 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(86): error c2227: left of '->show' must point class/struct/union/generic type 1> spl_project.cpp 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(85): error c2512: 'spl_project::form1' : no appropriate default constructor available 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(86): error c2027: use of undefined type 'spl_project::form1' 1>
c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(11) : see declaration of 'spl_project::form1' 1>c:\users\seuntech\documents\visual studio 2010\projects\spl_project\spl_project\form2.h(86): error c2227: left of '->show' must point class/struct/union/generic type

code below

 #pragma once namespace spl_project {  using namespace system; using namespace system::componentmodel; using namespace system::collections; using namespace system::windows::forms; using namespace system::data; using namespace system::drawing;  ref class form1; // /// <summary> /// summary form2 /// </summary> public ref class form2 : public system::windows::forms::form {   public:     form2(void)     {         initializecomponent();         //         //todo: add constructor code here         //     }  protected:     /// <summary>     /// clean resources being used.     /// </summary>     ~form2()     {         if (components)         {             delete components;         }     } private: system::windows::forms::button^  button1; protected:   private:     /// <summary>     /// required designer variable.     /// </summary>     system::componentmodel::container ^components;  #pragma region windows form designer generated code     /// <summary>     /// required method designer support - not modify     /// contents of method code editor.     /// </summary>     void initializecomponent(void)     {         this->button1 = (gcnew system::windows::forms::button());         this->suspendlayout();         //          // button1         //          this->button1->location = system::drawing::point(176, 205);         this->button1->name = l"button1";         this->button1->size = system::drawing::size(75, 23);         this->button1->tabindex = 0;         this->button1->text = l"button2";         this->button1->usevisualstylebackcolor = true;         this->button1->click += gcnew system::eventhandler(this, &form2::button1_click);         //          // form2         //          this->autoscaledimensions = system::drawing::sizef(6, 13);         this->autoscalemode = system::windows::forms::autoscalemode::font;         this->clientsize = system::drawing::size(284, 262);         this->controls->add(this->button1);         this->name = l"form2";         this->text = l"form2";         this->resumelayout(false);        } #pragma endregion private: system::void button1_click(system::object^  sender, system::eventargs^  e) {               form1 ^ na2 = gcnew form1();              na2->show();           } }; 

}

you must seperate implementation of button1_click declaration.

so put in "form2.h" declaration regarding "button1_click":

private: system::void button1_click(system::object^  sender, system::eventargs^ e); 

and remove "formward definition" of "form1" in "form2.h"

and create new file form1.cpp contains implementation, includes "forms2.h":

this content of "form2.cpp":

#include "form2.h" #include "form1.h"  namespace form2::spl_project {   system::void button1_click(system::object^  sender, system::eventargs^ e) {     form1 ^ na2 = gcnew form1();     na2->showdialog(this);   } } 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -