private is non-virtual: Stuck in C++-thinking?
Jonathan M Davis
jmdavisProg at gmx.com
Fri Oct 19 16:14:21 PDT 2012
On Friday, October 19, 2012 23:22:26 monarch_dodra wrote:
> According to TDPL, this should be legal. In particular, there is
> an entire section about it regarding NVI.
>
> No idea what it going on, but I'm curious for answers.
For interfaces, where it's doing something to specifically enable NVI. It never
says that for classes.
It's been discussed a number of times before, and I think that it's fairly
clear that Walter has no intention of changing it. Regardless, it would
actually be a _huge_ problem for private to be virtual, and it's completely
unnecessary for NVI (protected does the job just fine). If private were
virtual, then it that would kill inlining and any other optimization relying
on knowing the body of the function or anything else which gets affected by a
function being virtual - including the cost of the vtable lookup. You would be
forced to mark all private functions as final to fix this, which most people
won't do, which would lead to performance hits everywhere where classes are
used. Classes in D would be less performant for essentially _zero_ gain.
If you want virtual but don't want the function to be public, then use
protected.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list