How to use Private Inheritence aka C++ in C# and Why not it is present in C#
- by Vijay
I know that private inheritance is supported in C++ and only public inheritance is supported in C#. I also came across an article which says that private inheritance usually defines a HAS-A relationship and kind of an aggregation relationship between the classes.
EDIT: C++ code for private inheritance:
The "Car has-a Engine" relationship can also be expressed using private inheritance:
class Car : private Engine { // Car has-a Engine
public:
Car() : Engine(8) { } // Initializes this Car with 8 cylinders
using Engine::start; // Start this Car by starting its Engine
};
Now, Is there a way to create a HAS-A relationship between C# classes which is one of the thing that I would like to know - HOW?
Another curious question is why doesn't C# support the private (and also protected) inheritance ? - Is not supporting multiple implementation inheritance a valid reason or any other?
Is private (and protected) inheritance planned for future versions of C#?
Will supporting the private (and protected) inheritance in C# make it a better and widely used language?