D - more or less power than C++?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Mar 4 10:39:40 PST 2006


"Dave" <Dave_member at pathlink.com> wrote in message 
news:duci1c$22ao$1 at digitaldaemon.com...
> I'm not sure what you mean by 'auto class members', but if you meant 
> 'classes
> instantiated on the stack for which the dtor is automatically called when 
> they
> go out of scope', then I agree.

I think he means "class reference members whose lifetime is determined by 
the lifetime of the object that refers to them.  i.e.

class A
{
    auto B b;

    this()
    {
        b = new B();
    }

    ~this()
    {
        writefln("A dtor");
    }
}

class B
{
    ~this()
    {
        writefln("B dtor");
    }
}

void main()
{
    {
        auto A a = new A()
    }
    writefln("Done");
}

Would print

A dtor
B dtor
Done

(Or maybe the order of the dtors would be different, but the point is that 
the instance of B's lifetime is dependent upon the instance of A's.) 





More information about the Digitalmars-d mailing list