Private classes?

Nathan Reed nathaniel.reed at gmail.com
Tue Aug 21 01:20:49 PDT 2007


Hello,

I'm not sure if this is the appropriate mailing list on which to post this, so please tell me if it's not.

I have been playing around with D in the last few days and found that there doesn't seem to be any way to hide a class in a module using 'private'.  For example, using the DMD version 2.003, the following compiles without errors:

module A;
private class Foo
{
}
------------
module B;
import A;
...
auto f = new Foo;    // expected: error, Foo is private

If A has a privately declared *variable* and I try to access it from B, I get the expected error.

The same thing happens with inner classes; the following compiles without errors:

class Foo
{
    private class Bar
    {
    }
}
...
auto f = new Foo;
auto b = f.new Bar;   // expected: error, Bar is private

Now, I can't find anyplace in the D spec where it says that 'private' ought to work on classes...so I suppose this isn't technically a bug.  However, it seems like the sort of thing that one ought to be able to do.

Thanks,
Nathan Reed



More information about the Digitalmars-d mailing list