private method in interface
Steven Schveighoffer
schveiguy at yahoo.com
Thu Jun 2 10:31:58 PDT 2011
On Thu, 02 Jun 2011 13:10:14 -0400, Michael Shulman
<viritrilbia at gmail.com> wrote:
> Hi,
>
> The following code fails the linker, complaining about an undefined
> reference to 'foo':
>
>
> interface A {
> private int foo();
> }
>
> class B {
> int bar(A x) { return x.foo(); }
> }
>
> void main() { }
>
>
> But if I remove the 'private' qualifier on 'foo', then it succeeds.
> Shouldn't B.bar() be able to access the private A.foo(), since they
> are in the same package? If I move the definition of A into another
> package, then the *compiler* fails with "interface member not
> accessible", as I would expect.
Private methods are non-virtual, so I'm pretty sure they are not supposed
to be allowed in an interface.
But I suppose private could also mean private final, in which case you
have to provide an implementation for foo in the interface.
This would be in line with the error message.
-Steve
More information about the Digitalmars-d-learn
mailing list