Re: Wrong delete called for exported class that has virtual destructor.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/5/19 Wallace Wang <Wallace.Wang@xxxxxxxxxxxx>:
>
> Symptoms:
> When allocating and deleting an object of a class that is exported from a DLL, you may find that the new operator in the EXE is called to allocate the memory but the delete operator in the DLL is called to delete the memory. Therefore, there is a new/delete mismatching problem, which may cause run-time errors.
>
> I don't like the idea to override the new/delete operators in all of my classes. It is a huge change and may require multiple inheritance. Any other suggestion?
>

If you only pass a shared_ptr out of the DLL, instead of a raw one,
that shared_ptr keeps a pointer to the DLL's delete, so no matter
where it ends up getting deleted the correct delete gets called.

That has all sorts of other consequences, so YMMV.

~ Scott


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux