Re: denying inheritance

From: Micah Cowan (micah_at_cowan.name)
Date: 10/30/03


Date: 30 Oct 2003 12:12:57 -0800


"Gary Labowitz" <glabowitz@comcast.net> writes:

> "Micah Cowan" <micah@cowan.name> wrote in message
> news:m33cdbu8rx.fsf@localhost.localdomain...
> > "Novice" <cassidy@cs.queensuDOTca> writes:
> >
> > > Is there a way (in C++) to stop developers from being able to derive a
> class
> > > that you create?
> > Simply don't declare them "virtual". They'd still be able to
> > derive from the class, and still override the member
> > functions... BUT, when accessed as your original class type,
> > *your* functions are still the ones that will be called, since
> > their non-virtualness means that the implementation won't bother
> > checking to see if there are "newer" versions of those functions.
> >
> > Not having a virtual destructor really should keep sane people
> > from deriving from your class most of the time, I hope.
>
> Dumb question: can you inherit from a class if you don't have the source? Or
> a header?

Only if you otherwise define the class in your source, *exactly*
as originally defined. If you
don't have some access to class information, this is pretty much
impossible, so in short, the answer is "No."

-- 
Micah J. Cowan
micah@cowan.name


Relevant Pages

  • RE: VS 2005 Classname Drop down
    ... In VB.NET 2005, to override a method/property in an inherited class, open ... member in the list. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.general)
  • Overriding interface members
    ... And I want to override ... Declaring the member with override, ... my interface member completely replaces the member ... from the base class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: denying inheritance
    ... "Micah Cowan" wrote in message ... and still override the member ... Dumb question: can you inherit from a class if you don't have the source? ...
    (alt.comp.lang.learn.c-cpp)
  • Re: IDE and compiler for MAC
    ... In article, Gary Labowitz ... It looks, however, like he has to be a member of some club. ... >are no dues shown, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: .equals(o) and Set membership
    ... in which i have override the Object.equals ... > objects) and if another member of the class contains the same two objects ... > if i'm correct in reading the docs about how Set classes work, ... > method, which at runtime should bind to my overridden method, no? ...
    (comp.lang.java)