[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]
RE>Re- Constructor bombs f
- To: <heh@xxxxxxxxxxx>
- Subject: RE>Re- Constructor bombs f
- From: Mark S. Miller <vlad!mark>
- Date: Fri, 29 Jun 90 19:44:41 PDT
- Cc: <michael@xxxxxxxxxxx>, <xtech@xxxxxxxxxxx>
- In-reply-to: 03 <9006292202.AA22582@xanadu>
Date: 29 Jun 90 09:58:03
From: heh <xanadu!xanadu.com!heh>
...
Foo::Foo () {
pz = NULL;
px = NULL;
pz = zip ();
px = zap ();
}
Foo::~Foo () {
if (pz != NULL) {
delete pz;
}
if (px != NULL) {
delete px;
}
}
A slight modification which makes it more robust by being more
equivalent to Michael's recommended style of "progess" use:
Foo::Foo ()
: pz(NULL), px(NULL) // necessarily before BLASTs & non-BLASTing
{
PLANT_CONSTRUCTOR_BOMB(); // you forgot this
pz = zip ();
px = zap ();
}
Foo::~Foo () {
if (pz != NULL) {
delete pz;
pz = NULL; // In case we blast out of the destructor later & retry
}
if (px != NULL) {
delete px;
px = NULL; // In case we blast out of the destructor later & retry
/* actually, this one isn't necessary since its last, but */
/* if the code is later edited, it would be easy to forget */
/* add it. */
}
}
Waddaya think? How about having NULL member initializers generated
from the translator? (For CHKPTRs, NULL initialization already happens
implicitly.) Michael, please be gentle {-%