Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting C++/CLI code between .h and .cpp file

Is it possible to split a form class code between .h and .cpp file in C++/CLI like we do with native C++

When I do that I get parse error in the designer view.

like image 466
Rohini Sreekanth Avatar asked May 08 '26 06:05

Rohini Sreekanth


1 Answers

Yes you can.

Let the method definition in header, for example the constructor and destructor:

Form1(void);
~Form1();

and create a .cpp file, or just edit an existing : include "formName.h" (dont forgot namespace), next:

Form1::Form1(void)
{
    // ...
}

Form1::~Form1()
{
   // ...
}

For events (Click, Load, etc) load the event, keep definition of method in header and put the implementation in source file.

.h:

System::Void Button_Click(System::Object ^sender, System::EventArgs ^e);

.cpp:

Void Button_Click(Object ^sender, EventArgs ^e)
{
    MessageBox::Show("Hello, world !");
}
like image 136
ArthurCPPCLI Avatar answered May 09 '26 22:05

ArthurCPPCLI