Re: Idiots
Leigh Johnston wrote:
"Pete Becker" <pete@versatilecoding.com> wrote in message
news:C6qdneVYJctMrFvWnZ2dnUVZ_uqdnZ2d@giganews.com...
Leigh Johnston wrote:
"Jerry Coffin" <jerryvcoffin@yahoo.com> wrote in message
news:MPG.262fce2033a2e17f989884@news.sunsite.dk...
You're conflating two rather different things here. At least as far
as I've seen, nobody has said interface augmentation, as a basic
idea, is particularly wrong. What I've seen people say is that the
standard container classes don't have (for an obvious example)
virtual destructors, so public inheritance from them must be handled
with care that's so extreme that you're frequently better off
considering other options.
std::iterator is meant to be derived from and it does not have a
virtual destructor.
std::iterator is not a *standard container class*, so this does not
respond to the assertion made in the text you quoted. Nevertheless:
Not having a virtual destructor does not preclude inheritance.
Of course not. But there's no reason whatsoever for someone to want to
create a pointer to an std::iterator object, since it has no member
functions and no data. So there is no danger of deleting an object of
a derived type through a pointer to that base.
Yes without a virtual destructor in the base you invoke undefined
behaviour when deleting an object through a pointer to that base which
is why you don't do it. It is a rule that you simply have to remember
if you want to derive from classes that do not have a virtual
destructor. Bjarne Stroustrup has no problem with this (unless he has
retracted what he wrote in "The C++ Programming Language") and neither
do I.
Well, you certainly claim to be in good company. But given your
proclivity for misstatements (whether subsequently amended or not), I'm
skeptical that this is, in fact, true. Nevertheless, I'm delighted to
hear that you have no problem remembering not to delete such objects.
However, please allow for the fact that mere mortals may not share your
skill or your luck, and a prophylactic rule can sometimes be beneficial.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of
"The Standard C++ Library Extensions: a Tutorial and Reference"
(www.petebecker.com/tr1book)