Re: Class Destructor doesn't destroy?
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Fri, 25 Jan 2008 09:33:45 -0500
"Gerry Hickman" <gerry666uk@xxxxxxxxxxxxxxxx> wrote in message
news:uER06v1XIHA.536@xxxxxxxxxxxxxxxxxxxx
If I instantiate a Class using operator new, I can destroy it with
operator delete, but if I instantiate it without operator new, I don't
seem to be able to destroy it until it goes out of scope - manually
calling the destructor doesn't completely destroy it.
More precisely, your program exhibits undefined behavior under C++
stanadard 3.8/8:
If a program ends the lifetime of an object of type T with static
(3.7.1) or automatic (3.7.2) storage duration and if T has a non-trivial
destructor, the program must ensure that an object of the original type
occupies that same storage location when the implicit destructor call
takes place; otherwise the behavior of the program is undefined.
"Undefined behavior" here means the program can do anything, including
calling the destructor twice. See also
http://www.faqs.org/docs/jargon/N/nasal-demons.html
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- Class Destructor doesn't destroy?
- From: Gerry Hickman
- Class Destructor doesn't destroy?
- Prev by Date: Re: compile error about destructor
- Next by Date: Re: Class Destructor doesn't destroy?
- Previous by thread: Class Destructor doesn't destroy?
- Next by thread: Re: Class Destructor doesn't destroy?
- Index(es):
Relevant Pages
|