Why private methods cant be virtual?

Simen Kjærås simen.kjaras at gmail.com
Tue Sep 22 14:00:40 UTC 2020


On Tuesday, 22 September 2020 at 13:19:10 UTC, Daniel Kozak wrote:
> So final private functions can be overriden? It seems not, but 
> the sentence is definitely confusing if not just plain wrong.

Yeah. I've seen this called hiding, shadowing and overwriting 
earlier, but never overriding - that's always been reserved for 
the polymorphic kind.

I'd argue the documentation should use one of those other terms.


>  And yes compiler probably could findout that method could be 
> made
> non-virtual but I am not sure how easy is this and how it would 
> slow down
> compilation times

Steve showed a few posts up one example that would make it 
basically impossible. Other language features make it even worse:

     class A { private void fun() {} }
     class B(string s) : A { mixin(s); }

--
   Simen


More information about the Digitalmars-d-learn mailing list