Re: Virtual Destructor - Implication & Specification
On Apr 4, 3:05 pm, "Maxim Yegorushkin" <maxim.yegorush...@gmail.com>
wrote:
Those functions can be overloaded operator delete/new of that class.
Standard solution and it seems that it would clearly convey the
intent. This solution has already been mention here. Is it not good
enough?
Overloading new/delete for a class will _not_ help with the new/delete
mismatch problem in Windows, and probably other OS's. This is what I
keep saying. There are apparently expert and advance C++ programmers
who do not understand what Stroustrup wrote.
Let me be very clear.
If you overload new/delete for a class and manufacture an object of
that class in the DLL and return a pointer to that object to the EXE,
after which the EXE applies operator delete to the pointer, *** the
program will crash ***. You *** have *** to supply a virtual
destructor to keep the program from crashing. This is what Stroustrup
was trying to get across on page 421-422 of his book. At no point did
Stroustrup ever state that providing class-specific new/delete would
help with problems that are _only_ solved by a virtual destructor. It
is extremely unfortunate that so many advanced C++ programmers
interpret his text as such.
Now, if you make the destructor virtual, that is *all* you have to do
to provide class-specific new and delete.
If any of you are reading this and thinking, "Chaud's technique is
application specific and will only work on Windows..", I have news for
you: You *have* to do something that is "implementation specific" on
Windows to get this to work anyway.
It is my opinion that making the destructor virtual is the least
painful "implementation-specific" method of achieving the desired
results.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]