On 4/22/2015 12:15 PM, K. Frank wrote:
> A couple of quick questions:
>
> override:
>
> If starting with a clean slate, would it have made
> sense to make the use of override mandatory?
"Would it *have made* sense"? Why subjunctive? Why not just "does it
make sense"?
Yes, it does make sense just as much as without it. I suppose you are
referring to a convention of some kind, or a coding standard... Those
are like religion. If I don't like your standards, I won't work for
your group. If I care to work for your group more than I care to argue
with your standards, I will follow your standards... No more and no less.
> (I understand that making it mandatory would have
> severely broken backward compatibility.)
I struggle to comprehend your tenses and moods, sorry. Coding standards
are rarely retroactive. If you want to fix the existing code to force
adherence to some kind of a standard, it's done in maintenance and a
certain protocol (with lots of reviews and testing) should be
established. And it's a topic for 'comp.software-eng' more than for
c.l.c++...
>
> That is:
>
> struct A {
> virtual void f();
> virtual void g();
> };
>
> struct B : A {
> void f() override; // remains legal with mandatory override
> void g(); // not legal with mandatory override
> };
>
> (I like override -- state your intentions, make code more
> readable, help catch errors -- but would have making it
> mandatory have been going to far?)
No.
> final:
>
> I understand that there is debate about whether using
> final ever makes sense, but leaving that aside:
>
> Would declaring a virtual function final in a base class
> ever make sense? I.e.,
>
> struct A {
> virtual void f() final;
> };
>
> The only thing I can think of would be to force A to
> be a "polymorphic" class, e.g., trigger RTTI, etc.,
> but this seems pretty contrived.
If the calling code is to be left unchanged, and the struct A is to be
left untouched, and A::f is not declared 'final', then I can circumvent
the call to that function by deriving from A and overriding 'f'. The
only way to ensure that 'f' is called by the caller (without changing
the calling code) is to declare 'f' final. It's a rare situation, but I
am sure it's encountered often enough to justify that feature to exist
in the language.
V
--
I do not respond to top-posted replies, please don't ask