Convert Multiple Derived Class into CLI/C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ed

    #1

    Convert Multiple Derived Class into CLI/C++

    Hi, dear all,
    Now there is a issue to convert C++ into CLI/C++. But there is a issue
    block me.

    Say Class MN is multiple derived from class MM and NN. But the CLI
    only allow single class derived.

    My understanding is to create a new interface INN with same method
    declaration with class NN.
    And let class MN derived from MM and INN, then copy the implementation
    of NN method into class MN. And also make class NN derived from
    interface INN.

    But this method is ugly I think.

    Is there some nice way to make a nice migration to CLI code?

    Thank you in advance!

  • Carl Daniel [VC++ MVP]

    #2
    Re: Convert Multiple Derived Class into CLI/C++

    Ed wrote:
    Hi, dear all,
    Now there is a issue to convert C++ into CLI/C++. But there is a issue
    block me.
    >
    Say Class MN is multiple derived from class MM and NN. But the CLI
    only allow single class derived.
    >
    My understanding is to create a new interface INN with same method
    declaration with class NN.
    And let class MN derived from MM and INN, then copy the implementation
    of NN method into class MN. And also make class NN derived from
    interface INN.
    >
    But this method is ugly I think.
    >
    Is there some nice way to make a nice migration to CLI code?
    Not much nicer, no. One thing that could help a little bit is rather than
    re-implementing INN, hold an instnace of NN as a private member and write
    simple forwarders for the implementation of INN. That's essentially what
    the compiler does under the hood for multiple inheritance anyway.

    In practice, multiple inheritance should be rare - if you've got a codebase
    with lots of multiple inheritance, you'll have a rough time converting it
    all to CLI code.

    Keep in mind though, that you don't have to convert all of your classes to
    'ref class'. Only those classes that need to be accessible from other .NET
    assemblies need be converted - the C++/CLI compiler can still compile your
    multiply-inherited classes in a /clr build, but those classes will not be
    managed by the CLR - they'll still live on the native heap (or stack) and
    their lifetimes will have to be managed by you (no garbage collection).

    -cd


    Comment

    • =?Utf-8?B?RGF2aWQgQW50b24=?=

      #3
      RE: Convert Multiple Derived Class into CLI/C++

      There is no elegant way to directly convert multiple inheritance to single
      inheritance + interfaces. It would be better to refactor so that you truly
      have single inheritance + interfaces instead of trying to simulate multiple
      inheritance.
      --
      David Anton
      Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

      Convert between VB, C#, and C++
      Instant C#
      Instant VB
      Instant C++
      C++ to C# Converter
      C++ to VB Converter


      "Ed" wrote:
      Hi, dear all,
      Now there is a issue to convert C++ into CLI/C++. But there is a issue
      block me.
      >
      Say Class MN is multiple derived from class MM and NN. But the CLI
      only allow single class derived.
      >
      My understanding is to create a new interface INN with same method
      declaration with class NN.
      And let class MN derived from MM and INN, then copy the implementation
      of NN method into class MN. And also make class NN derived from
      interface INN.
      >
      But this method is ugly I think.
      >
      Is there some nice way to make a nice migration to CLI code?
      >
      Thank you in advance!
      >
      >

      Comment

      • Ed

        #4
        Re: Convert Multiple Derived Class into CLI/C++

        On 8 9 , 10 08 , David Anton <DavidAn...@dis cussions.micros oft.com>
        wrote:
        There is no elegant way to directly convert multiple inheritance to single
        inheritance + interfaces. It would be better to refactor so that you truly
        have single inheritance + interfaces instead of trying to simulate multiple
        inheritance.
        --
        David Antonhttp://www.tangiblesof twaresolutions. com
        Convert between VB, C#, and C++
        Instant C#
        Instant VB
        Instant C++
        C++ to C# Converter
        C++ to VB Converter
        >
        "Ed" wrote:
        Hi, dear all,
        Now there is a issue to convert C++ into CLI/C++. But there is a issue
        block me.
        >
        Say Class MN is multiple derived from class MM and NN. But the CLI
        only allow single class derived.
        >
        My understanding is to create a new interface INN with same method
        declaration with class NN.
        And let class MN derived from MM and INN, then copy the implementation
        of NN method into class MN. And also make class NN derived from
        interface INN.
        >
        But this method is ugly I think.
        >
        Is there some nice way to make a nice migration to CLI code?
        >
        Thank you in advance!

        Thanks for all of you! So there is no elegant way to handle it.

        MN should inherit from MM and INN, and put the NN implementation into
        MN class.

        Comment

        Working...