What's the secret to static class members

Guido via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jun 29 08:33:58 PDT 2016


On Wednesday, 29 June 2016 at 15:18:53 UTC, Guido wrote:
> I'm using a static class member in a parent class, but can't 
> get the compiler to see it.
>
> Class Grid{
>   public:
>   uint xdim;
> }
>
> Class Holder : Grid {
>   uint var;
> }
>
> Any of the following should work, but none of them do:
> Grid.xdim = 0;
>
> grid = new Grid;
> grid.xdim = 0;
>
> holder = new Holder;
> holder.xdim = 0;
>
> This is the way static class vars were intended to work. What 
> magics have I forgotten?
>
> Platform
> DMD latest, Windows 7
> Visual D

The problem is actually much more profound. The classes need to 
be declared outside the main() scope. WTF?!?!?!

I put them in main() so they would be in scope. This seems like a 
*MAJOR* design flaw with the language, not to mention the 
compiler not giving useful feedback. This decision, if it is a 
decision, makes no sense given all the attention to scoping rules.

I'm not interested in trading one set of bad language decisions 
for another. Can someone fix this?


More information about the Digitalmars-d-learn mailing list