Question about RAII.
Derek Parnell
derek at psych.ward
Tue Jul 4 06:13:26 PDT 2006
On Tue, 04 Jul 2006 23:05:58 +1000, Peter C. Chapin <pchapin at sover.net>
wrote:
> Hello! I'm a C++ programmer who has started to look at D. I appreciate
> many of D's design decisions. However, I'm a little confused about how
> RAII is supported. It seems like it only semi-works. Consider the
> function below ('Example' is some class):
The 'auto' in this context means "destroy the local member when it goes
out of scope". This may or may not correlate to your RAII definition but
that's what 'auto' means in D. It doesn't matter if the object is in use
or not, if it goes out of scope it is destroyed. So in the situation you
describe, you will be required to explictly delete the object you no
longer want and do not use 'auto'.
Of course, another method is to only create the object when you know which
one to create.
--
Derek Parnell
Melbourne, Australia
More information about the Digitalmars-d
mailing list