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: 
I am sorry to disagree with the comments and answers saying that it is not possible for a `static const` symbol to be initialized at program startup rather than at compile time.

Actually this IS possible, and I used it many times, BUT I initialize it from a configuration file. Something like:

```
// GetConfig is a function that fetches values from a configuration file
const int Param1 = GetConfig("Param1");
const int MyClass::Member1 = GetConfig("MyClass.Member1");

```

As you see, these static consts are not necessarily known at compile time. They can be set from the environment, such as a config file.

On the other hand, setting them from argv[], seems very difficult, if ever feasible, because when main() starts, static symbols are already initialized.
No, you cannot do that.

> 
> If this cannot be done what is the type of variable I should use ?
> 
> 
> 

You can use a non-`const` member.

```
class A 
{
   public: 
      static int T;
};

int A::T;

```

Another option is to make `T` a private member, make `main` a friend so only it can modify the value, and then expose the member through a function.

```
#include <cstdlib>

class A 
{
   public: 
      static int getT() { return T; }
   private:
      static int T;
      friend int main(int argc, char** argv);
};

int A::T;

int main(int argc, char** argv)
{
   A::T = std::atoi(argv[1]);
   return 0;
}

```