0

I have main window. main.cpp

#include "mainWindow.h"

using namespace System;
using namespace System::Windows::Forms;

int main()
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Client::mainWindow mainWin;
    Application::Run(%mainWin);
    return 0;
}

And i have another form, which should open when the main form openning:

mainWindow.h

private: System::Void mainWindow_Shown(System::Object^  sender, System::EventArgs^  e) {
        Client::logForm^ myForm = gcnew logForm();
        myForm->Show();
        //Client::logForm logF;
        //logF.Show();
    }

And my question: why using the commented code, the form opens and closes immediately, but uncommented code works good?

Thank you!

MSalters
  • 173,980
  • 10
  • 155
  • 350
mrglut
  • 27
  • 5
  • It is an undefined behaviour for C++ . Possible duplicate :http://stackoverflow.com/questions/5360501/c-function-called-without-object-initialization – Zigma Mar 09 '15 at 12:01
  • no, it is not a duplicate question. – mrglut Mar 09 '15 at 12:55
  • You don't understand how stack semantics work, you got it wrong both in your Main() method and the commented code. Read [this post](http://stackoverflow.com/a/28686756/17034). – Hans Passant Mar 09 '15 at 13:00

0 Answers0