Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't shared_ptr have a virtual descructor? (and how can I get around this?)
    primarykey
    data
    text
    <p>I wanted to make a special version of <code>shared_ptr</code> that would perform specific operations when it was created or destroyed, but my plans appear to be foiled by the realization that <code>shared_ptr</code>'s destructor is non virtual, meaning when I override it, my pointers never get cleaned up when the last instance of them are destroyed.</p> <p>The only alternative that comes to mind is to build in this behavior into every class that I want to use with my hypothetical custom <code>shared_ptr</code>, and that's not feasible (or possible in some cases). </p> <p>Edit:</p> <p>The reason I want this is because I want to use some classes as userdata objects in lua, and I want each one of my objects that I use this way to have a fenv table unique to it that will be cleaned up when all references to the object have been removed. I plan on using the address of the pointer as they key into a table that holds the fenv table.</p> <p>Lets say I have a widget that can have other widgets as children. I create two widgets in Lua, then set one as the child of the other and remove all lua references to the child widget (the fact that it's a child is handled in C++). The GC can now run at any time and remove the child. I don't necessarily want the child to have it's destructor run though, so I want to make it a shared_ptr. That way, C++ objects can still use it after Lua has cleaned it up. If I've assigned values or functions to it's fenv I still want to be able to access them. Only when the final reference to my child widget is removed do I want the fenv tabled to be removed totally.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload