Package and virtual functions
Jonathan M Davis
jmdavisProg at gmx.com
Wed Jun 13 16:16:35 PDT 2012
On Thursday, June 14, 2012 01:07:17 BLM768 wrote:
> On Wednesday, 13 June 2012 at 22:48:34 UTC, Jonathan M Davis
>
> wrote:
> > On Thursday, June 14, 2012 00:32:45 BLM768 wrote:
> >> For some reason, whenever I declare a method with package
> >> visibility, it becomes non-virtual. Is this normal behavior, or
> >> is there a bug in DMD 2.059?
> >
> > Only public and protected functions can be virtual. private and
> > package
> > functions are never virtual. This is by design.
> >
> > - Jonathan M Davis
>
> That explains it. I kind of wish I'd known that a few hours ago :)
> It would be nice if DMD would issue a warning when redefining a
> non-virtual function in a subclass. I might have to start using
> "override" more often despite force of habit and dislike of its
> verboseness. Perhaps "override" should be implied by default
> since it's by far the most common case. In cases where the
> programmer really wants to redefine the function non-virtually,
> there could be a keyword that would handle that. It could reduce
> extra typing and save beginners hours of stress :)
override will eventually be required when overriding a function. It is already
if you compile with -w but not yet all of the time - though since protected
isn't virtual and isn't really overriding anything, the compiler doesn't
complain if you don't use override with it (though it will if you do, since
it's not overriding anything). So, eventually (or now if you use -w), you will
_always_ know whether a function is overiding another or not, because it will
have to have override if it is and can't have it if it isn't.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list