classes inside functions?!

Sean Kelly sean at f4.ca
Wed May 3 12:47:49 PDT 2006


Bruno Medeiros wrote:
> 
> I see. Hum, can a local variable (local to a function) be external?

Sort of.  A static local variable has external linkage in D (and I think 
in C++ as well, though the meaning of 'static' is a bit different 
there).  Here's an example:

     import std.c.stdio;

     template templ( alias A )
     {
         void templ()
         {
             printf( "%i\n", A );
         }
     }

     int i = 5;

     void main()
     {
         templ!(i);

         int j = 6;
         templ!(j);
     }

Change the "int j = 6" to "static int j = 6" and everything compiles.


Sean



More information about the Digitalmars-d mailing list