Package functions cannot be abstract?!

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Jan 30 14:44:14 UTC 2019


On Tuesday, January 29, 2019 9:05:15 PM MST Jonathan Levi via Digitalmars-d 
wrote:
> Why in the world can abstract functions not be only visible to
> only a package?
>
> I have a public abstract class which has private implementations.
>   Some abstract member functions are needed for use withing the
> package but should not be visible publicly.
>
> What is the point of making this not possible?!  Is it more
> difficult to implement or is just a random limitation for the
> heck of it?
>
> Do you have a recommendation on how to do what I am trying to do?
>
> Thanks.
>
> ```
> class Cls {
>      package abstract void fun(string a){};
> }
> ```
> Error: function `onlineapp.A.a` package functions cannot be
> abstract

By design, only public and protected functions are virtual. private and
package functions are not. As such, they cannot be overridden, and it makes
no sense to allow them to be abstract. For better or worse, D went the
simplified route of tying whether a function is virtual or not to its access
level. For the most part, this makes sense, but there are cases where you
lose flexibility as a result.

- Jonathan M Davis





More information about the Digitalmars-d mailing list