[Understanding] Classes and delegate inheritance vs function pointers
sighoya
sighoya at gmail.com
Sun Jan 10 13:54:13 UTC 2021
On Sunday, 10 January 2021 at 00:44:26 UTC, Q. Schroll wrote:
>
> Car[] cars = ...;
> Vehicle[] vehicles = cars;
> vehicles[0] = new Boat; // err...
> // cars[0] is a Boat now!?
>
> Now what? Do what Java does and throw an Exception? Or use
> const to prevent mutation?
Yes, you are right:
```
Derived derived;
Base* bp=&derived;
*bp=base;
derived.method() //ouch
```
> I'm unsure what you mean.
I mean D doesn't support co(ntra)varaince out of the box, but
seems allowing them in certain cases increasing the degree of
confusion just as it is the case here.
I think it would be just better to generally incorporate
co(ntra)variance into D's semantic or completely disregard it.
More information about the Digitalmars-d-learn
mailing list