From -6004229032307239041
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,c9300cc6a0b28243
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-08-05 07:38:24 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!newsfeed.mathworks.com!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: richard@ex-parrot.com (Richard Smith)
Newsgroups: comp.std.c++
Subject: Re: no_base_call
Date: Tue, 5 Aug 2003 14:38:22 +0000 (UTC)
Organization: Posted via Supernews, http://www.supernews.com
Lines: 42
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <Pine.LNX.4.55.0308051056300.32223@sphinx.mythic-beasts.com>
References: <_azXa.385380$jp.11007710@twister.southeast.rr.com>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Trace: mail2news.demon.co.uk 1060094303 12640 10.0.0.1 (5 Aug 2003 14:38:23 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Tue, 5 Aug 2003 14:38:23 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.12)
	id 19k2xB-0003Hj-00
	for mail2news@news.news.demon.net; Tue, 05 Aug 2003 14:38:22 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id AAA15092; Wed, 6 Aug 2003 00:38:18 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ucar.edu
X-Newsgroups: comp.std.c++
X-X-Sender: richard@sphinx.mythic-beasts.com
X-Spam-Status: No, hits=-6.2 required=5.0
	tests=AWL,BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES,
	      REPLY_WITH_QUOTES,USER_AGENT_PINE
	version=2.55
X-Spam-Checker-Version: SpamAssassin 2.55 (1.174.2.19-2003-05-19-exp)
Xref: archiver1.google.com comp.std.c++:20465

Jeff Williams wrote:

> Often when over-riding functions from a base class, I find it difficult to
> easily determine if I should be calling the base class version (in the case
> of a hook) or not calling the base class version (in the case of changing
> behavior).

Use the private virtual function idiom, then.  Basically,
this says that a virtual function should be private unless
you want to be able to call it non-virtually from an
overriding implementation, in which case it should be
protected.  If the virtual function should be callable from
outside the base class, then a public (or maybe just
protected) forwarding function should be provided.

This idiom provides a number of advantages.  There's minimal
danger of accidentally making a non-virtual function call
when a virtual one was intended.  It provides a single place
to place code to assert preconditions and insert other code
that is common to all overrides.  It provides better
segregation between the "implementation interface" (i.e.
the virtual functions that subclasses override) and the
"external interface" (i.e. the public functions that users
of the class call).  Finally, it can assist in the use of
patterns that reduce dependencies, such as the Bridge
pattern.

> It occurred to me that it might be useful to provide an additional function
> type specifier that I shall refer to as no_base_call.

No need for it.  If you following the advice above, you
shouldn't get into problems.

--
Richard Smith

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



