Re: Testing Program Question
On Feb 16, 11:49 am, "Leigh Johnston" <le...@i42.co.uk> wrote:
It is a nonsense to say that virtual functions shouldn't be
public: a public virtual destructor is fine if you want to
delete through a base class pointer.
The destructor is an obvious exception. But most experts today
generally agree that virtual functions should usually be either
protected or private.
Again, there are exceptions, and I have classes with only public
virtual functions. (Callbacks are a frequent example.) But
they're just that: exceptions.
You are talking garbage sorry: saying "print" is an exception
or callbacks (abstract interfaces) are an exception is just
wrong.
Print may be an exception, but I'm not convinced. I think
various call inversion sequences are a definite exception. But
a lot of the experts disagree with me, and do insist that
virtual functions never be public. (Look at the std::streambuf
hierarchy, for example.)
These are only "exceptions" to some stupid rule that
only a subset of the C++ community happen to agree with
including yourself.
The "subset" includes most of the experts. People like Herb
Sutter, for example.
As I disagree with this rule they are not exceptions in but
simply normal C++ coding practice.
Normal for inexperienced programmers, perhaps, or those who
don't care about quality.
--
James Kanze