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