From 3842298756013105428
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8c9f1307b83ac2db
X-Google-Attributes: gidf78e5,public
From: Mark Wilden <Mark@mWilden.com>
Subject: Re: Q: virtual functions not overridable anymore?
Date: 1997/10/02
Message-ID: <342C48EF.75AF@mWilden.com>#1/1
X-Deja-AN: 277375548
References: <01bcb109$1e790180$433574cf@worldnet.worldnet.att.net> <3404A0AE.6F7E@Eng.Sun.COM> <5uimip$l56@bgtnsc03.worldnet.att.net> <340D93AA.643A@Eng.Sun.COM> <01bcb951$ea80a440$909c389d@mtayler> <ocr4t7zlk2o.fsf@ml.com> <34166C9E.1882@pratique.fr> <341E7C8E.EA4@pratique.fr> <3420858D.12DB@mWilden.com> <34293558.73F@pratique.fr>
X-Original-Date: Fri, 26 Sep 1997 16:44:47 -0700
Originator: austern@isolde.mti.sgi.com
Organization: The Mark Wilden Company
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNDPNZEy4NqrwXLNJAQGAJQH+IL+LLqABPnPgx+koWr7pCzTmEQtA+kyy 15x65VwolpDNicW9Q8QPQ92M5wc38uypoa7/3WpeoL2+bvrFMlRpzw== =vn+x
Newsgroups: comp.std.c++


Valentin Bonnard wrote:
> 
> Mark Wilden <Mark@mWilden.com> writes:
> 
> > Valentin Bonnard wrote:
> 
> > > You might want to declare Dialog::draw () final as at this point,
> > > behaviour should be changed by deriving from DialogItem, not Dialog.
> >
> > That would prevent you from doing something like this:
> >
> >  struct DebugDialog : Dialog {
> >     void draw()
> >     {
> >         cout << "About to draw dialog" << endl;
> >         Dialog::draw();
> >         cout << "Done drawing dialog" << endl;
> >     }
> >  };
> 
> But any non-virtual function prevents you from doing that.

Yes, which is a good argument to why member functions should be virtual
by default. :)

> virtual functions aren't a way to patch program to remove
> bugs or to introduce debugging tests; they are a way to
> write OO programs where the derived class define a function
> the correct way.

Do you have any supporting references for that opinion? In any event, if
the derived class's purpose is to debug the parent class (perhaps
because the parent source isn't available), then my example does indeed
define the function the correct way.

I'm not saying I use derivation for debugging very often, mind you; I'm
just asking why disallow it?

> Remember: the original argument was: since we have
> non-virtual functions, we should have final functions
> (ie non-virtual functions overiding from virtual
> functions).

That's true. I was just pointing out what I saw as a flaw in the example
given, that "behaviour should be changed by deriving from DialogItem,
not Dialog." That's not necessarily true.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



