Question: Is it possible to initialize a static const member of my class during run-time? This variable is a constant throughout my program but I want to send it as a command-line argument. 

```
//A.h
class A {
public: 
    static const int T;
};

//in main method
int main(int argc,char** argv)
{
    //how can I do something like 
    A::T = atoi(argv[1]);
}

```

If this cannot be done, what is the type of variable I should use? I need to initialize it at run-time as well as preserve the constant property.

Answer: 
Typically you will have more than one configuration value. So put them in a struct, and the normal global access to it is const.

```
const config* Config;
...
main (int argc, char* argv [])
{
Config= new config (argc, argv);
...
}

```

You can get fancier and have a global *function* to return config, so normal code can't even change the pointer, but it is harder to do that by accident.

A header file exposes `get_config ()` for all to use, but the way to set it is only known to the code that's meant to do so.
There is a trick, but you should probably avoid it! Here's a bare bones example to illustrate the principle:

```
int const& foo(int i) {
    static const int j = (i == 0 ? throw 0 : i); 
    return j; 
}

int main() {
    try { 
        int x = foo(0); // oops, we throw        
    } catch(...) {}

    int x = foo(1); // initialized..
    int y = foo(0); // still works..     
}

```

Careful!