Why is a static struct's dtor called at the exit of a function?
Jacob Carlborg
doob at me.com
Thu Jul 21 23:45:44 PDT 2011
On 2011-07-22 08:12, Diego Canuhé wrote:
> Hi,
> I'm not really an experienced programmer so I might be missing something
> but...
>
> in
> http://d-programming-language.org/attribute.html
> static is described as follows:
>
> "The static attribute applies to functions and data. It means that the
> declaration does not apply to a particular instance of an object, but to
> the type of the object. In other words, it means there is no this
> reference. static is ignored when applied to other declarations."
>
> What I understand from that text is that static only applies to
> functions and data *of a class
> *
> As far as I'm concerned static only makes a method non-virtal and a
> variable a class-variable.
> (static if has nothing to do with this static. I think)
>
>
> If I just talked nonsense out of my ignorance, I apologize
> Static data has only one instance for the entire program, not once per
> objec
static can be applied to data as well, also in global functions:
import std.stdio;
void foo ()
{
static int i;
writeln(i++);
}
void main ()
{
foo();
foo();
}
Will print
0
1
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list