
Martin Bonner wrote:
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Caleb Epstein Sent: 12 October 2006 22:09 To: boost@lists.boost.org Subject: Re: [boost] Boost super_string
On 10/12/06, Arkadiy Vertleyb <vertleyb@hotmail.com> wrote:
More importantly, according to the standard, the basic_string class destructor is not virtual, and so basic_string is not intended for derivation. Wouldn't this only matter if super_string added data members (it doesn't AFAICT) Not relevent.
It is relevant. If you add data members you now want to ensure the subclass destructor runs in the case below. Detailed completely in Effective C++ #14.
and was being deleted via pointers to std::basic_string?
THIS is the relevent point.
string* pstr = new super_string; delete pstr;
is undefined behaviour. In practise, you get away with it if super_string doesnt do anything in its destructor,
Exactly.
and if all additional members don't do anything in their destructors. However, formally it is ALWAYS undefined behaviour.
The real question is how often will people create a super_string on the heap, and delete it through pointer to string.
No. The intent is that the above new/delete is supported. If it isn't then it's a really bad idea. Jeff