C ++ / CLI: inherits one CLR class, multiple C ++ classes

In C ++ / CLI, I want the class hierarchy to look like the following:

Foo FooA : Foo, ClrClassA FooB : Foo, ClrClassB 

Is it possible that FooA will share the base class (not the CLR) and also inherit from the individual CLR classes? If not, how could FooA and FooB share common code?

+3
source share
2 answers

Generally speaking, composition is often better than inheritance , since it tends to lead to less closely related projects.

If you mix managed and unmanaged code, in my experience it is usually easier to port unmanaged code in managed code, and not vice versa.

Multiple inheritance is not supported for managed code, and a Wikipedia article that explains why:

Managed C ++ and the use of classes and class-based objects remains common, as in Visual C ++. The only major change in Managed C ++ is that multiple inheritance capabilities are not supported. This is due to the limitation of CLR. CLR garbage collector managed class cannot inherit more than one class

It is hard to give a good answer on how best to combine your classes / functionality without knowing why you want to combine classes ...

+5
source

You cannot inherit a class from both a reference and a native.

+3
source

Source: https://habr.com/ru/post/951231/


All Articles