digitalmars.D.learn - private final class destructors
- bearophile (19/19) Aug 19 2010 According to TDPL the whole object destructor chain is called up to the ...
- Simen kjaeraas (5/23) Aug 19 2010 A destructor is always final, and private destructors make no sense,
- bearophile (4/6) Aug 19 2010 Thank you for your answer, I have added the test case to bug 3934
- Jonathan M Davis (7/9) Aug 19 2010 Actually, I could see private destructors making at least some sense. Ob...
According to TDPL the whole object destructor chain is called up to the top of the hyerarchy. This D2 program compiles and runs with DMD 2.048 with no errors: import std.c.stdio: puts; class Base { private final ~this() { puts("Base.~this"); } } class Derived : Base { private final ~this() { puts("Derived.~this"); } } void main() { new Derived(); } Output: Derived.~this Base.~this Are the 'private final' attributes used here correct? See also: http://d.puremagic.com/issues/show_bug.cgi?id=3934 Bye, bearophile
Aug 19 2010
bearophile <bearophileHUGS lycos.com> wrote:According to TDPL the whole object destructor chain is called up to the top of the hyerarchy. This D2 program compiles and runs with DMD 2.048 with no errors: import std.c.stdio: puts; class Base { private final ~this() { puts("Base.~this"); } } class Derived : Base { private final ~this() { puts("Derived.~this"); } } void main() { new Derived(); } Output: Derived.~this Base.~this Are the 'private final' attributes used here correct? See also: http://d.puremagic.com/issues/show_bug.cgi?id=3934A destructor is always final, and private destructors make no sense, so I would say the attributes should not be there. -- Simen
Aug 19 2010
Simen kjaeraas:A destructor is always final, and private destructors make no sense, so I would say the attributes should not be there.Thank you for your answer, I have added the test case to bug 3934 Bye, bearophile
Aug 19 2010
On Thursday, August 19, 2010 08:23:42 Simen kjaeraas wrote:A destructor is always final, and private destructors make no sense, so I would say the attributes should not be there.Actually, I could see private destructors making at least some sense. Obviously, the runtime needs to be able to call them, but I could see someone wanting to make it so that a destructor could not be explicitly called by the programmer. I'm not sure that that's ultimately all that useful, but I could see private destructors working that way. - Jonathan M Davis
Aug 19 2010