Re: Virtual Destructor - Implication & Specification
jaibuduvin@gmail.com (Le Chaud Lapin) wrote (abridged):
However, it is conceivable that one could write a function that simply
calls new() for a One object, then returns that pointer from a DLL to
the EXE.
That's what I was trying to show - one compilation unit being in the DLL,
the other in the EXE.
However, one could argue that this method of engineering is
inappropriate, that one should be cognizant of various scenarious and
avoid putting the class definition into a static lib, and and put it
only inside a DLL.
I see. It sounds like you are putting the code into a static library and
then linking it into two DLLs at once. Microsoft's dynamic linker doesn't
sort this out, so the final runtime has two definitions of the same
operator delete(). This is a violation of the One Definition Rule so we
would not expect it to work.
I agree with those who say this is an implementation-specific problem (ie
caused by Microsoft's approach to mixing static with dynamic linking), to
which you have found an implementation-specific solution.
Everyone who reads this thread ought also be aware of
boost::shared_ptr, which also provides a solution.
Even if the object that is being pointed to does not have a virtual
destructor?
Yes. It also works with predefined types like int. In effect, it captures
a pointer to the appropriate delete operator as the object is created. The
overhead of this is higher than with Virtually_Destructible. However, I
think it is more portable (it's part of tr1 now) and as guaranteed to work
as anything to do with dynamic linking.
-- Dave Harris, Nottingham, UK.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]