Article View: comp.std.c++
Article #2073Re: object contruction/destruction in c++, des
From: Steve Clamage
Date: Fri, 29 Sep 1995 17:26
Date: Fri, 29 Sep 1995 17:26
25 lines
1617 bytes
1617 bytes
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. ]
Technical Details
Message-ID:
<44ha4v$fv3@engnews2.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<henk_kampman-2909951146290001@huisie-ppp1.knoware.nl>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: object contruction/destruction in c++, des Date: 29 Sep 1995 17:26:05 GMT Organization: Sun Microsystems Inc. Approved: matt@physics2.Berkeley.EDU (Matt Austern) Message-ID: <44ha4v$fv3@engnews2.Eng.Sun.COM> References: <henk_kampman-2909951146290001@huisie-ppp1.knoware.nl> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: physics2.berkeley.edu