digitalmars.D.learn - static class Foo {}
- mandel (7/7) Dec 02 2007 Hi,
- bearophile (5/8) Dec 02 2007 I may agree, usually.
- mandel (18/19) Dec 02 2007 Local namespaces have their purpose as
- Jarrett Billingsley (25/32) Dec 02 2007 Inside another class, static classes are classes without outer pointers.
- mandel (4/8) Dec 02 2007 Ok, that's behaviour I expected.
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
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
bearophile wrote:D has modules and packages as Python, use them.Local namespaces have their purpose as 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
"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
Jarrett Billingsley wrote:Inside another class, static classes are classes without outer pointers.Ok, that's behaviour I expected. But not quite as I hoped regarding to the outside declaration. [..]Outside, static does nothing.
Dec 02 2007