Topic: object contruction/destruction in c++, des


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/09/29
Raw View
In article 2909951146290001@huisie-ppp1.knoware.nl, henk_kampman@idsys.nl (Henk Kampman) writes:
>
>Why is the destructor only called for fully contructed objects?
>To my oppinion this results in code duplication in the contructor and destructor

If a constructor exits via an exception, those portions of the object
which were automatically constructed (base classes and members having
constructors) are automatically destroyed. I hope it is obvious that after
that point the destructor for the complete object must not be invoked.

If you choose to exit a constructor via an exception, and have created
in your own code some objects which should be destroyed, it is up to you
to destroy those objects. I don't see how an automatic mechanism could
know what to do. (Maybe all of those objects should be destroyed, maybe
none of them should be destroyed.)
---
Steve Clamage, stephen.clamage@eng.sun.com



---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]