Static members and access attribute

Sergey Gromov snake.scaly at gmail.com
Fri Oct 24 05:47:09 PDT 2008


Fri, 24 Oct 2008 13:05:00 +0100,
Bruno Medeiros wrote:
> Uriel wrote:
> > I've found some strange behaviour with static members and haven't noticed anything about it in the documentation.
> > 
> > module a;
> > 
> > class A
> > {
> >     private static int Foo;
> > }
> > 
> > import std.stdio;
> > 
> > import a;
> > 
> > void main()
> > {
> >     A.Foo = 1;
> >     writeln(A.Foo);
> > 
> > /*    
> >     A obj = new A();
> >     obj.Foo = 2;
> >     writeln(A.Foo);
> > */
> > }
> > 
> > Program will compile and print '1'. But if uncomment the second part of code compiler will say that "class a.A member Foo is not accessible".
> > Is this a bug?
> 
> No, Foo is private, so you can't access it outside of the module where 
> it is defined (module a).

Of course it's not a bug that the commented-out part fails.  It's a bug 
that the first part of main() works.



More information about the Digitalmars-d mailing list