~= call copy ctor?

Ali Çehreli acehreli at yahoo.com
Fri Jul 20 15:03:35 PDT 2012


On 07/20/2012 02:54 PM, Namespace wrote:
> On Friday, 20 July 2012 at 21:51:02 UTC, David Nadlinger wrote:
>> On Friday, 20 July 2012 at 21:41:45 UTC, Namespace wrote:
>>> Why comes "DTOR class" _after_ "end main" and not before?
>>> If i write "scope TestC c = ...;" it is correct, but i read that
>>> "scope" will be deprecated. Can someone explain me that behaviour?
>>
>> The destructor will be invoked when the GC collects the object,
>> not when the last reference to it goes »out of scope«.
>>
>> David
>
> Really? Holy crap...
> Can i correct this? And will "scope" for classes really
> deprecated?

The truth is, the destructor may not ever be called.

Yes scope is (will be?) deprecated and is replaced by std.typecons.scoped:

import std.typecons;
// ...
         auto c = scoped!TestC();


Prints:

begin scope
CTOR class
CTOR struct
end scope
DTOR struct
DTOR class
end main

Ali


More information about the Digitalmars-d-learn mailing list