CLI,How to divide a class into multi-files(like c# partial)
-
How to divide a class into multi-files(like c# partial)? I want to divide class MainForm into multi-files? Could somebody tell me how do I achieve this goal?
namespace MyTools {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Globalization;//for NumberFormatInfovector<MyData> m_MyData;
public ref class MainForm : public System::Windows::Forms::Form
{ -
How to divide a class into multi-files(like c# partial)? I want to divide class MainForm into multi-files? Could somebody tell me how do I achieve this goal?
namespace MyTools {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
using namespace System::Globalization;//for NumberFormatInfovector<MyData> m_MyData;
public ref class MainForm : public System::Windows::Forms::Form
{akira32 wrote:
How to divide a class into multi-files(like c# partial)?
C++ or C++/CLI already supports this. One header file and several source files is possible. You can have a
MainFormUI.cpp
which includesMainForm.h
and have methods likeInitializeComponent
. Another source file sayMainForm.cpp
which has all other method implementations. Unfortunately, VS designer won't support this kind of separation and it will always write the auto-generated code to MainForm.h.Navaneeth How to use google | Ask smart questions
-
akira32 wrote:
How to divide a class into multi-files(like c# partial)?
C++ or C++/CLI already supports this. One header file and several source files is possible. You can have a
MainFormUI.cpp
which includesMainForm.h
and have methods likeInitializeComponent
. Another source file sayMainForm.cpp
which has all other method implementations. Unfortunately, VS designer won't support this kind of separation and it will always write the auto-generated code to MainForm.h.Navaneeth How to use google | Ask smart questions
A C# Partial Class is not equivalent to the C++ & C++/CLI header/source model. The following cannot not be done with C++ or C++/CLI in different (or in the same) files:
// In source file X:
public partial class Employee
{
public void DoWork()
{
}
}// In source file Y
public partial class Employee
{
public void GoToLunch()
{
}
}"We make a living by what we get, we make a life by what we give." --Winston Churchill
-
A C# Partial Class is not equivalent to the C++ & C++/CLI header/source model. The following cannot not be done with C++ or C++/CLI in different (or in the same) files:
// In source file X:
public partial class Employee
{
public void DoWork()
{
}
}// In source file Y
public partial class Employee
{
public void GoToLunch()
{
}
}"We make a living by what we get, we make a life by what we give." --Winston Churchill
George L. Jackson wrote:
A C# Partial Class is not equivalent to the C++ & C++/CLI header/source model.
I never said they are equal.
George L. Jackson wrote:
The following cannot not be done with C++ or C++/CLI in different (or in the same) files:
Correct because it needs all the functions to be declared before using. The question here is How to divide a class into multi-files(like c# partial)? and I believe C++'s header and multiple source files model is the answer. Please correct me if you feel it is wrong. :)
Navaneeth How to use google | Ask smart questions
-
George L. Jackson wrote:
A C# Partial Class is not equivalent to the C++ & C++/CLI header/source model.
I never said they are equal.
George L. Jackson wrote:
The following cannot not be done with C++ or C++/CLI in different (or in the same) files:
Correct because it needs all the functions to be declared before using. The question here is How to divide a class into multi-files(like c# partial)? and I believe C++'s header and multiple source files model is the answer. Please correct me if you feel it is wrong. :)
Navaneeth How to use google | Ask smart questions
It depends on the point of view, just having multiple physical files or having both multiple physical files and the method of class construction. Yes, you can use multiple files (header/source) in C++ as you do in C#. However, the C# partial class is constructed more like a C++ class-namespace hybrid where you can define methods and data members in multiple source files that somehow come together in the scope of one class.
"We make a living by what we get, we make a life by what we give." --Winston Churchill