On Fri, Nov 20, 2009 at 12:59 PM, Peter Kasting <pkast...@google.com> wrote:

> On Fri, Nov 20, 2009 at 12:42 PM, Mark Mentovai <m...@chromium.org> wrote:
>
>> As Evan points out, there are some cases when it's not absolutely
>> necessary to have a base or interface class declare a virtual
>> destructor.
>
>
> For a concrete example, take AutocompleteEditController, which is declared
> in autocomplete_edit.h.  This is an abstract base class that names several
> different methods.  The purpose of the class is to insulate the
> functionality the edit needs from whatever code actually implements that
> functionality.  However, the edit doesn't create or own pointers to its
> controller, and never deletes its controller, so this abstract class doesn't
> have a virtual destructor.  The pattern here is "implements interface X" as
> opposed to the "is a specialized type of an X" pattern of parent and child
> classes.
>

What's the benefit of omitting the virtual destructor?

This seems inherently error-prone since you are relying on users of the
class to stick to a behavior that is subtle (never destroy through a pointer
to the base class), undocumented, and impossible for the compiler to
enforce.  Alternately, you could have the compiler enforce that an object of
this type is never deleted through a pointer to the base class by declaring
a protected destructor, instead of leaving in the compiler-defined public
default one.  I'm not sure why you would want to do this over just declaring
a virtual d'tor.

- James


>
> PK
>
> --
> Chromium Developers mailing list: chromium-dev@googlegroups.com
> View archives, change email options, or unsubscribe:
> http://groups.google.com/group/chromium-dev
>

-- 
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev

Reply via email to