<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 22, 2020 at 3:05 PM claptrap via Digitalmars-d-learn <<a href="mailto:digitalmars-d-learn@puremagic.com">digitalmars-d-learn@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
The thread title is...<br>
<br>
"Why private methods cant be virtual?"<br>
<br>
IE Not...<br>
<br>
"how do I override private functions in a non-polymorphic manner."<br>
<br>
And what you suggest wont work because I was asking about virtual <br>
functions, so I specifically want polymorphism. And FWIW it's no <br>
big deal I can just use protected, i wasn't looking for a <br>
solution, I was looking for an explanation as to why it was done <br>
that way. But apparently there is none.<br><br></blockquote><div><br></div><div>And I did not try to show solution. It was just an answer to this part of your response:</div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">So final private functions can be overriden? It seems not, but</span><br style="color:rgb(80,0,80)"><span style="color:rgb(80,0,80)">the sentence is definitely confusing if not just plain wrong.</span><br></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">So the reason why there is this:</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">"Functions marked as final may not be overridden in a derived</span><br style="color:rgb(80,0,80)"><span style="color:rgb(80,0,80)"> class, unless they are also private"</span><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">Is because with private methods final keyword has no meaning.</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)">And there is a reason "</span>Why private methods cant be virtual?<span style="color:rgb(80,0,80)">".</span></div><div><span style="color:rgb(80,0,80)">It is because it would break existing code. And because  private methods are final it makes them fast.</span></div><div><span style="color:rgb(80,0,80)"> 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</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div><span style="color:rgb(80,0,80)"><br></span></div></div></div>