D classes inherane. How it works.
Jason House
jason.james.house at gmail.com
Tue Apr 8 09:24:22 PDT 2008
D uses virtual functions by default (and C++ does not). Most of your code is showing virtual function handling vs. non-virtual function handling.
I'm unclear on how flush is getting called at all.
kov_serg Wrote:
> Sorry, for silly question by could anyone give link where I could found how D constructor and destructors works. The behavious is very nice but much different from C++.
>
> import std.stdio;
>
> class A {
> void init() { writefln("A.init"); }
> void fn() { writefln("A.fn"); }
> void flush() { writefln("A.flush"); }
> this() { writefln("A");init(); }
> ~this() { flush();writefln("~A"); }
> }
>
> class B : A {
> void init() { writefln("B.init"); }
> void fn() { writefln("B.fn"); }
> void flush() { writefln("B.flush"); }
> this() { writefln("B"); }
> ~this() { writefln("~B"); }
> }
>
> void main() {
> writefln("D1.0 main");
> A a=new B;
> a.fn();
> delete a;
> }
> /*
>
> D1.0 main
> A
> B.init
> B
> B.fn
> ~B
> B.flush
> ~A
>
> C++ version
> A
> A.init (no B vft yet)
> B
> B.fn
> A.flush (dtor overrides vft)
> ~A
>
> */
>
> ps: C++ version more strong but hardly usefull. D version looks much better for me. But how it implemented or should be implemented. If ~B already kills his resources?
More information about the Digitalmars-d
mailing list