Stroustrup is disappointed with D :(
Ola Fosheim Grøstad via Digitalmars-d
digitalmars-d at puremagic.com
Tue Sep 22 23:06:41 PDT 2015
On Tuesday, 22 September 2015 at 23:21:20 UTC, Steven
Schveighoffer wrote:
> Yeah, but you can't do this in C++ though:
>
> class D : B {
> this()
> {
> writeln("derived is only now complete");
> super();
> }
> }
>
> I find the ability to control the construction order far more
> important than virtual calls for base constructors.
You could do it in old C++ compilers, and some have a permissive
switch that allows you to do it, but you should not do it. It
leads to incorrect initialization and breaks encapsulation
(unsound typing). Forcing construction order is a Good Thing.
In Beta, the successor to Simula, all execution follows this
pattern:
this(){
begin_prepare_stuff();
subclass.this();
end_prepare_stuff();
}
This way the superclass defines what you can override which is
better for correctness.
More information about the Digitalmars-d
mailing list