www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - static class Foo {}

reply mandel <oh no.es> writes:
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.
Dec 02 2007
next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
mandel:
 I thought I could use it like the C++ namespace keyword.

D has modules and packages as Python, use them.
 Things that do not have an effect should result in compiler
 warnings or even errors.

I may agree, usually. Bye, bearophile
Dec 02 2007
parent mandel <oh no.es> writes:
bearophile wrote:

 D has modules and packages as Python, use them.

nested classes and functions do have. Having files/modules for them is a blunt instrument. I thought of static class Foo { uint a; uint b; } as a shortcut for smth. similar to class Foo { static uint a; static uint b; } But with the difference that a "static class" wouldn't allow to be instanciated (singleton out fo the box).
Dec 02 2007
prev sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"mandel" <oh no.es> wrote in message news:fiumjg$2uol$2 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.
Dec 02 2007
parent mandel <oh no.es> writes:
Jarrett Billingsley wrote:
 
 Inside another class, static classes are classes without outer pointers.

But not quite as I hoped regarding to the outside declaration. [..]
 
 Outside, static does nothing.

Dec 02 2007