Can we just have struct inheritence already?
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Jun 10 08:18:28 UTC 2019
On Monday, 10 June 2019 at 07:26:29 UTC, Andrei Alexandrescu
wrote:
> On 6/9/19 5:13 PM, Manu wrote:
>> This is NOT polymorphism, we're not talking about
>> polymorphism, I wish
>> people would not change the topic.
>
> The problem here is that it's difficult to define subtyping
> without polymorphism. C++ does technically allow it, but code
> such as:
>
> struct my_vector : public std::vector<int> { ... }
>
> is universally reviled. I really think it wouldn't help D much
> to add struct inheritance.
Not a the best example. Inheriting from your own vector
implementation is fine, except that C++ has a weak and broken
type system, so templated inheritance does not work properly (you
have to list all the members you want visible in the subclass
which is very annoying).
Inheriting from the standard C++ library is bad because:
- the type was not designed with inheritance in mind
- the type may have new members added since it is in the standard
library
- the compiler might special case it, since it is the standard
library
Anyway, lots of things that are "universally reviled" in C++ is
related to weaknesses in the C++ language design/type system.
More information about the Digitalmars-d
mailing list