How to write a proper class destructor?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Jan 26 07:10:51 PST 2007


Jonas Kivi wrote:
> Frits van Bommel kirjoitti:
>> Jonas Kivi wrote:
>>> And about the scope keyword on a class member suggestion: What about 
>>> the "auto" keyword. What's the difference between the auto and the 
>>> scope keywords?
>>
>> "scope" is for automatic deletion. "auto" is for type inference.
>> "auto" used to also be for automatic deletion, but its dual purpose 
>> was annoying, especially when you wanted to have both of its meanings 
>> apply (which wasn't possible).
>> "auto" may still do automatic deletion when a type is also supplied, 
>> I'm not sure, but if so that's just for backwards compatibility. Don't 
>> use it for that in new code.
> 
> 
> Ahh, thanks for clearing that up. I changed all the auto-keywords in my 
> own projects code to scope. There were some 50 of them. I'm not sure. It 
> looked like it had some effect on my program, so maybe the auto keyword 
> doesn't even work for it's old purpose anymore? Don't know. But thanks, 
> now I only have my destructors unfunctional.

Well, one way to make sure a class never gets GC'ed is to make it a 
'scope class'. Then you can only keep references as scope variables, and 
they always get explicitly deleted. The only problem is that you're then 
not allowed to keep them in member variables, just function-local vars.


More information about the Digitalmars-d-learn mailing list