Re: Virtual Destructor - Implication & Specification
On 2 Apr, 08:36, "Le Chaud Lapin" <jaibudu...@gmail.com> wrote:
A while back I originated a post about a Virtual_Destructor<> wrapper
template whose purpose was simply to add a no-op virtual destructor to
a class. Using it. at least under Microsoft Windows, circumvents the
new/delete heap mismatch problem.
If I understand correctly, the problem stems from allocating *memory*
from one heap and returning it to another. The natural way to solve it
would be to allocate and deallocate memory from the same translation
unit, would not it?
Over the years I have had repeated arguments with colleagues who
emphatically insist that making the destructor of a class virtual
under Windows will *not* eliminate the heap mismatch problem, and each
time, I have to write an EXE and a companion DLL to prove that it
does.
While it may work, it does not seem to be an elegant solution. The
reason being that C++ distinguishes between allocating/deallocating
raw memory and initializing/deinitializing an object in that memory.
The destructor is a means of the latter, not the former. By trying to
affect deallocation using means of deinitialization relying on a
platform specific behavior rather than the standard, imho, only
obscures the problem.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]