Re: Good style for memory management?

On Sun, 2007-03-18 at 17:50 +0100, Roland Schwarz wrote:

> that if finding an error in the file throws out. Since you are not the
> author of the parser you either have to
> *) wrap everything in try {} catch() {} blocks or use
> *) resource acquisition is initialization idiom.

most good books on C++ that i have read which tackle this issue
recommend avoiding throwing out of constructors anyway. i think meyers
and others recommend constructing an object as minimally as possible and
then explicitly "initializing" it. this is in part precisely to deal
with the kind of ambiguity that you are encountering. thus, if you have

  class MyFancyWidget : public class Gtk::SomeWidget {.... }

you construct such a thing like this:

     MyFancyWidget* w = manage (new MyFancyWidget()); // does almost

     try {
         w->init (some, args, it, might, need);
     catch (....

since this allows you to handle exceptions cleanly and clearly.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]