On Friday, 2 January 2015 at 14:50:54 UTC, Suliman wrote:
Anything declared in main() is local to main and not a global.

Ok! So I need create multiple instances of the parseconfig?

Or please suggest me any solution, I really can't understand how to be in such situation...

Have you ever used a C-like programming language or are you a bloody beginner? So that I can figure out how basic the explanation has to be.

Basically every pair of {} introduces a scope. And you can only refer to things declared in the current or a parent scope.

{
   int x;
   {
       // x available here
   }
}
// x not available anymore

For your example this means that

void main()
{
     auto parseconfig = new parseConfig();
}
// parseConfig unavaiable since here

class whatever
{
   // cannot use parseconfig
}

What you can do is to declare the config outside any braces and make it a module global. But you'll need a module constructor (look them up in the docs). They are declared with this() outside of any scope in a module.

----
parseConfig parseconfig;

this()
{
    parseconfig = new parseConfig(...);
}

void main() { /* can use parseconfig */ }

class SomeClass { /* should be able to as well */ }
---

Reply via email to