c++ - Why doesn't shared_ptr have a virtual descructor? (and how can I get around this?) -


I wanted to create a special version of shared_ptr , when it was created, was destroyed , But my plan fails to achieve that the destroyer of shared_ptr is non-virtual, which means that when I override it, my pointers are never cleaned, When his last example is destroyed. / P>

The only option that comes to mind, is to create this class in every class that I want to use with my own fictional custom shared_ptr , and this is not possible (or Is possible in some cases).

Edit:

The reason for this is that I want to use some sections in Lua as UIIdata objects, and I want every one of my objects that I I use a unique foam table which will be cleaned when all the reference to the object will be removed. I am planning to use the pointer's address in the table containing the foreign table.

Let's say I have a widget that can have other widgets as kids. I made two widgets in Lu, then set one as the other's child and remove all the Lua references in the hair widget (the fact that this child is handled in C ++). GC can now run any time and can remove the baby. I do not necessarily want the child to run this district, so I want to share it. In this way, C ++ objects can still use it when Laa has cleaned it. If I have specified the value or function for this, then I still want to be able to reach them. When my child's final reference of the widget is removed, I want fenw to be completely removed.

It has already created this capability so that people need to get it like dangerous things Do not be.

  #include & lt; Boost / shared_ptr.hpp & gt; # Include & lt; Iostream & gt; / * * Simplicity is done as a function * but it can be done in many ways * / zero microlux (int * x) {std :: cout & lt; & Lt; "Complete \ n"; Remove x; } Int main () {boost :: shared_ptr & lt; Int & gt; X (new int (5), michlanup); }  

Problems with getting:
Just over the top of my head

Class X: Public Shared _ PPR & lt; Int & gt; {/ * STUFF with a special disaster; Int main () {/ What happens now? Similar to slicing but not enough * / x data 1 (new int (5)); Shared_ptr & lt; Integer & gt; Data2; Shared_ptr & lt; Integer & gt; Data3 (data); Data2 = Data 1; }

Comments