static class Foo {}

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Dec 2 09:07:45 PST 2007


"mandel" <oh at no.es> wrote in message news:fiumjg$2uol$2 at digitalmars.com...
> Hi,
>
> I like to ask of the meaning of
> static class Foo {}
> I thought I could use it like the C++ namespace keyword.
> But static doesn't seem to have an effect.
> Things that do not have an effect should result in compiler
> warnings or even errors.

Inside another class, static classes are classes without outer pointers.

class A
{
    int x;

    class B
    {
        void foo()
        {
            writefln(x); // works fine, accesses this.outer.x
        }
    }

    static class C
    {
        void bar()
        {
            writefln(x); // error, 'this' for 'x' needs to be of type 'A', 
not 'C'
        }
    }
}

Outside, static does nothing.

It's annoying that redundant attributes/protection specifiers are allowed by 
the compiler, but it supposedly makes generic code easier, mostly when 
dealing with mixins. 




More information about the Digitalmars-d-learn mailing list