static class
Steven Schveighoffer
schveiguy at yahoo.com
Sun Feb 17 14:20:25 PST 2013
On Sun, 17 Feb 2013 17:00:19 -0500, Michael <pr at m1xa.com> wrote:
>
>> That's not the meaning of static in that context.
> As I understand a static class can't be instantiated.
Static in that position is a no-op. The compiler (infuriatingly
sometimes) accepts attributes that have no meaning silently.
> So in mine case if I want purely static class I need to use:
>
> static Test
> {
> static void foo();
> }
A class that can't be instantiated has a private constructor. In
addition, if you want to make all the functions static, in D you can
either put them in a static scope, or use the colon:
class Test
{
private this() {}; // will never be instantiatable
static: // all members after this will be static. Could also use
static { ... }
void foo(); // a static function
int x; // a static variable
}
-Steve
More information about the Digitalmars-d-learn
mailing list