On Mon, 04 Oct 2010 14:29:38 -0400, Denis Koroskin <2kor...@gmail.com> wrote:

On Mon, 04 Oct 2010 22:26:17 +0400, Steven Schveighoffer <schvei...@yahoo.com> wrote:


What possible use case could private methods being polymorphic allow?

A private method can only be called by the class that contains the implementation. Allowing base classes to call it makes no sense.

Make the method protected, it gives the desired effect (including for the example in the bug report as stated by the original reporter).

-Steve


module private;
import std.stdio;

class A
{
        private void foo()
        {
                writeln("hi there");
        }
}

class B : A
{
        void test()
        {
                foo();
        }
}

void main()
{
        B b = new B();
        b.test();
}

# dmd private.d && ./private
hi there!

That works today (aside from using a keyword for the module name), there's nothing polymorphic about it.

I suppose you may be rebutting my "can only be called by the class that contains the implementation", yes, I immediately wished to change that sentence after I sent it out.

But you don't need polymorphism to achieve this.

-Steve

Reply via email to