Is this expected? default to public members in private class

Dan Olson via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 3 18:07:20 PDT 2015


It seems a private class or struct defaults to public members.  Just
curious if this is intended.  I would have expected private all the way
down unless overriden.

--- plugh.d
module plugh;
auto makeFoo() {return new Foo;}

private:

class Foo
{
    void maybepriv() {}
    private void priv() {}
    public void pub() {}
}

--- xyzzy.d
module xyzzy;
import plugh;

void main()
{
    auto f = makeFoo();
    f.maybepriv();      // is accessible after all
    //f.priv();         // err expected, member private
    f.pub();
}

--
Dan Olson


More information about the Digitalmars-d-learn mailing list