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. Managed C++/CLI
  4. CLI,How to divide a class into multi-files(like c# partial)

CLI,How to divide a class into multi-files(like c# partial)

Scheduled Pinned Locked Moved Managed C++/CLI
graphicsquestioncsharptutorial
5 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.
  • A Offline
    A Offline
    akira32
    wrote on last edited by
    #1

    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 NumberFormatInfo

    vector<MyData> m_MyData;

    public ref class MainForm : public System::Windows::Forms::Form
    {

    N 1 Reply Last reply
    0
    • A akira32

      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 NumberFormatInfo

      vector<MyData> m_MyData;

      public ref class MainForm : public System::Windows::Forms::Form
      {

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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 includes MainForm.h and have methods like InitializeComponent. Another source file say MainForm.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

      G 1 Reply Last reply
      0
      • N N a v a n e e t h

        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 includes MainForm.h and have methods like InitializeComponent. Another source file say MainForm.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

        G Offline
        G Offline
        George L Jackson
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • G George L Jackson

          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

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          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

          G 1 Reply Last reply
          0
          • N N a v a n e e t h

            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

            G Offline
            G Offline
            George L Jackson
            wrote on last edited by
            #5

            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

            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