WRT boost::shared_ptr<>, why not template the explicit constructor that takes a T*? This way, it could select the correct destructor at construction time: struct base { ~base(); }; struct sub : public base { ~sub() }; boost::shared_ptr<base>(new sub); The above code currently only calls ~base(); Templating the explicit single argument constructor would allow the above code to call ~sub(). The constructor now takes only a T*, and therefore populates the pointer to the destructor function with a call to ~T(), which is ~base() in the above example. If, however, the constructor took an X*, the above example would pass a sub*, and it could populate the default destructor function with a pointer to ~X(). Comments? Joshua Lehrer FactSet Research Systems NYSE:FDS
--- In Boost-Users@yahoogroups.com, "Lehrer, Joshua"
WRT boost::shared_ptr<>, why not template the explicit constructor that takes a T*? This way, it could select the correct destructor at construction time:
struct base { ~base(); }; struct sub : public base { ~sub() }; boost::shared_ptr<base>(new sub);
The above code currently only calls ~base(); Templating the explicit single argument constructor would allow the above code to call ~sub().
Why not just have a virtual destructor? Then delete will be able to destroy your derived class properly: struct base { virtual ~base(); }; Dan
participants (3)
-
d_zakaib
-
Lehrer, Joshua
-
Peter Dimov