For ressource management I mostly use this pattern, to ensure the destructor is run:

void myfunc(){
 MyClass X = new MyClass(); scope(exit) X.destroy;
}

I somewhere read, this would work too:

void myfunc(){
 auto MyClass X = new MyClass();
}

What does this "auto" does here? Wouldn't

void myfunc(){
 auto X = new MyClass();
}

be sufficient? And would this construct guarantee that the destructor is run? And if, why does "auto" has this effect, while just using "new" doesn't guarantee to run the destructor?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to