Convert Multiple Derived Class into CLI/C++

E

Ed

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!
 
C

Carl Daniel [VC++ MVP]

Ed said:
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
 
G

Guest

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
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, and C++
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
 
E

Ed

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.tangiblesoftwaresolutions.com
Convert between VB, C#, and C++
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top