[lug] new operator in C++
Scott A. Herod
herod at interact-tv.com
Mon Apr 29 14:32:02 MDT 2002
Peter Hutnick wrote:
>
> Let me preface my comments by saying that I am inexperienced, naive, and
> un-knowledgeable programmer, so when I use question marks below I am really
> asking a question.
>
> Isn't initializing /everything/ within the code the only responsible thing to
> do? Preferably to a logical nonsense value that you can easily test for?
Absolutely! Imagine the case:
class c {
c( void );
~c( void );
object* _op;
};
c::c() {}
c::~c() { delete _op; }
int main() {
C* c = new C();
delete c;
}
Admittedly, I've done at least two bad-things(TM), but this code will
potentially corrupt memory.
Scott
> That, of course, would have no impact on whether you should code to depend on
> that behavior.
>
> Can anyone tell me where my thinking is off track here?
>
> - -Peter
More information about the LUG
mailing list