Re: Odd behavior, vector member, MFC and consol app
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sun, 12 Aug 2007 14:40:07 -0400
Good points. I was concerned that the storage problem might be due exactly to having
someone call the base class destructor which then ended up doing something bad.
joe
On Sun, 12 Aug 2007 12:46:34 -0500, "Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote:
On Sun, 12 Aug 2007 00:16:26 -0400, Joseph M. NewcomerJoseph M. Newcomer [MVP]
<newcomer@xxxxxxxxxxxx> wrote:
Note that destructors should also be virtual.
joe
... if they need to be. The only reason to make a destructor virtual is to
allow a derived class object to be deleted through a pointer to a base
class subobject. For this to work, the base class in question must have a
virtual destructor. If a class is not intended for derivation (1), such as
CString or std::vector, it should have no virtual functions at all. If a
class is meant to be derived from as a pure composition technique, such as
boost::noncopyable and std::iterator, it should not have a virtual dtor
(2).
(1) A good clue that a class is not intended for derivation is the absence
of any virtual function.
(2) An exception to (1) is (2). The boost::noncopyable class is really a
workaround for the lack of something like the CLR's "attributes" in C++,
while std::iterator just declares a bunch of typedefs that ease iterator
definition. To be useful, you must derive from them, but it's not
derivation for OOP reasons.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Odd behavior, vector member, MFC and consol app
- From: Dan Bloomquist
- Re: Odd behavior, vector member, MFC and consol app
- From: Doug Harrison [MVP]
- Re: Odd behavior, vector member, MFC and consol app
- From: Dan Bloomquist
- Re: Odd behavior, vector member, MFC and consol app
- From: Joseph M . Newcomer
- Re: Odd behavior, vector member, MFC and consol app
- From: Doug Harrison [MVP]
- Odd behavior, vector member, MFC and consol app
- Prev by Date: Re: Too many Post Messages causing app not to refresh
- Next by Date: Re: Where to call SetWindowPos
- Previous by thread: Re: Odd behavior, vector member, MFC and consol app
- Next by thread: Re: Odd behavior, vector member, MFC and consol app
- Index(es):
Relevant Pages
|