|
Boost Users : |
From: Darin Adler (darin_at_[hidden])
Date: 2002-09-22 00:30:39
On Friday, September 20, 2002, at 06:34 PM, zhangwusheng wrote:
> Why?And for what purpose?
> I cannot understand the following words:
>
> // verify that types are complete for increased safety
The rules in the C++ standard are that if you delete using a pointer in
a context where the type of the object pointed to is not completely
defined, the object will be deleted, but the destructor will not be
called. Many people think that's a particularly bad rule, because the
code compiles and runs, but does the wrong thing.
Since it contains a typedef that includes sizeof(T), this function will
fail to compile if the type T is not complete. This means that the
checked delete function template will only compile if the destructor
will be called. That way the compiler will detect a programming mistake
that would otherwise result in deleting the object without calling the
destructor. This is likely to save time that would otherwise be spent
debugging problems caused by destructors that are not called.
A lot of us are hoping that like a future version of the C++ standard
will make delete itself behave like this.
-- Darin
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net