C++ versions:

        { //displays ~C~B~A
            A foo;
            B bar;
            C *caz = new C();
            delete caz;
        }

        std::cout << std::endl;

        { //displays ~C~B~A
            std::unique_ptr<A> foo = std::make_unique<A>();
            std::unique_ptr<B> bar = std::make_unique<B>();
            C *caz = new C();
            delete caz;
        }


D version:

        { //displays ~A~B~C
            A foo = scoped!(A)();
            B bar = scoped!(B)();
            C caz = new C();
            destroy(caz);
        }

Why the objects are not destroyed in the inverse order of their creation? Case in point, destroying foo releases a lock for bar and caz.

Reply via email to