Re: STL non virtual DTOR
On 22 Feb., 20:21, "Sushrut Sardeshmukh" <bestbr...@gmail.com> wrote:
Why did STL designer chose not to make std:list DTOR virtual.
making its DTOR virtual will make our life easier, isn't it?
There is a reason destructors are not virtual by default: this gives
added overhead in memory footprint as well as execution time.
Apparantly, this overhead was deemed to large compared with to its
advantage. You might argue that this overhead is sufficiently small
compared to the "normal" use of a std::list, but I tend to agree with
the design: having a virtual destructor invites to inheritance and
polymorphic behaviour, and this is mostly wrong for the standard
containers. Use containment instead.
Also..
In which case I should do this and which case I should not.
class my_generic_list:: public std::list
Note that there is nothing wrong with this design. It is perfectly
safe to derive from std::list. The only problem is if you delete your
class with a pointer to std::list. All depends on the usage of your
class: as a "generic" class, I would recommend against it. In some
specific situation it might be fine.
/Peter
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]