Why can't we derive struct's?

Steven Schveighoffer schveiguy at gmail.com
Fri Dec 21 19:08:57 UTC 2018


On 12/20/18 10:08 PM, Walter Bright wrote:
> On 12/20/2018 6:55 AM, Steven Schveighoffer wrote:
>> really we should implement multiple-alias-this and that problem would 
>> be solved.
> 
> And create a host of other problems. Multiple alias this is multiple 
> inheritance with all of C++'s problems with it, and more, because then 
> you wind up with two (count 'em, 2!) multiple inheritance hierarchies. 
> Madness. Even single alias this has spawned a fair amount of wreckage in 
> bugzilla, because people use it for multiple inheritance which it was 
> never intended for.

The issues I've seen in bugzilla are how alias this overrides default 
expected behavior of classes. In other words, if you have a base class 
and want to cast it to a derived, and the base class has an alias this, 
it stupidly tries the alias this, and won't even consider a dynamic cast.

It's not madness so much as poor implementation. Saying there are bugs 
in the alias this implementation is not the same as saying the feature 
is problematic. All that is needed is a good definition of what takes 
precedence -- we already have that, it's just not implemented properly.

> MI is just a bad idea. It's best to just think of another way to 
> structure the data - even if you get it to work, it'll just confuse the 
> poor schlub who has to maintain the code.

But MI is not multiple alias-this. alias-this is more like an implicit 
cast, where as multiple inheritance has to deal with the diamond 
problem, and other issues (like the expectation of base types living at 
the same address as the derived one). Would you say that C++ operator 
conversions has all the same problems as MI?

-Steve


More information about the Digitalmars-d mailing list