Destructing Member Objects
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Apr 6 06:10:40 PDT 2008
"Brian White" <bcwhite at pobox.com> wrote in message
news:ft9oil$j0a$1 at digitalmars.com...
>> class foo
>> {
>> private ~this()
>> {
>> }
>>
>> public kill()
>> {
>> // call any specific code you want here
>> delete this;
>> }
>> }
>>
>> Then use foo.kill() instead of delete foo. Ugly, but works, I think.
>
> I don't think it does work. If you have a "scope" variable, for example,
> the compiler won't call "kill" when deleting the object.
You'd have to do it yourself.
{
auto f = new foo();
scope(exit) f.kill();
// ...
}
More information about the Digitalmars-d-learn
mailing list