Static member inside a class.

Steven Schveighoffer schveiguy at yahoo.com
Thu Jun 13 12:59:10 PDT 2013


On Thu, 13 Jun 2013 15:47:22 -0400, Agustin  
<agustin.l.alvarez at hotmail.com> wrote:

> I would like to know if static members are shared between 2 library. For  
> example:
>
> Class A
> {
>   static uint var;
> }
>
>  From Library A:
>
> A::var = 3;
>
>  From Library B:
>
> if( A::var == 3 )
>    ...
>
> Its this possible? if not, its any way to make it happend?

It's possible, and works just like you have it (syntax is slightly  
different, use A.var)

However, static means "thread local"  So you can't access the same A.var  
 from multiple threads.

To access from multiple threads, declare var like:

shared static uint var;

-Steve


More information about the Digitalmars-d-learn mailing list